Пример #1
0
def callback():
    flow.fetch_token(authorization_response=request.url)

    if not session["state"] == request.args['state']:
        abort(500)  # state does not match

    credentials = flow.credentials
    request_session = requests.session()
    cached_session = cachecontrol.CacheControl(request_session)
    token_request = google.auth.transport.requests.Request(
        session=cached_session)

    id_info = id_token.verify_oauth2_token(id_token=credentials._id_token,
                                           request=token_request,
                                           audience=GOOGLE_CLIENT_ID)

    session['google_id'] = id_info.get("sub")
    # if 'google_id' in session:
    #     app.permanent_session_lifetime = timedelta(seconds=5)
    # return redirect("/")
    #     start_time = datetime.datetime.now()
    #     end_time = start_time + datetime.timedelta(0,10)
    #     if start_time > end_time :
    #         print("time matched")
    #         session.pop("google_id",None)
    # print("session_id=",session['google_id'])
    # print("current_time=",start_time)
    # print("end _time =",end_time)
    session["name"] = id_info.get("name")
    return redirect("/protected_area")
Пример #2
0
def callback():
    flow.fetch_token(authorization_response=request.url)

    if not session["state"] == request.args["state"]:
        abort(500)  # State does not match!

    credentials = flow.credentials
    request_session = requests.session()
    cached_session = cachecontrol.CacheControl(request_session)
    token_request = google.auth.transport.requests.Request(
        session=cached_session)

    id_info = id_token.verify_oauth2_token(id_token=credentials._id_token,
                                           request=token_request,
                                           audience=GOOGLE_CLIENT_ID)

    session["google_id"] = id_info.get("sub")
    session["name"] = id_info.get("name")
    session["email"] = id_info.get("email")
    user = User.get_by_email(session["email"])
    if not user:
        user = User(email=session.get("email"),
                    password=generate_password_hash("google"),
                    full_name=session.get("name"),
                    phone_number=None)
        db.session.add(user)
        db.session.commit()
        last_user = User.query.order_by(User.user_id.desc()).first()
        session["user_id"] = last_user.user_id
        flash('Successfully signed up!', 'success')
    else:
        session['ia'] = user.is_admin
        session["user_id"] = user.user_id
    return redirect(url_for('index'))
Пример #3
0
def login_callback():
    if not flow:
        return redirect(url_for('.info'))
    flow.fetch_token(authorization_response=request.url)

    credentials = flow.credentials
    request_session = requests.session()
    cached_session = cachecontrol.CacheControl(request_session)
    token_request = google.auth.transport.requests.Request(
        session=cached_session)

    id_info = id_token.verify_oauth2_token(id_token=credentials._id_token,
                                           request=token_request)

    session['google_id'] = id_info.get('sub')
    session['name'] = id_info.get('name')
    return redirect('/')
Пример #4
0
def callback():
    flow.fetch_token(authorization_response=request.url)

    if not session['state'] == request.args['state']:
        abort(500)

    credentials = flow.credentials
    request_session = requests.session()
    cached_session = cachecontrol.CacheControl(request_session)
    token_request = google.auth.transport.requests.Request(
        session=cached_session)

    id_info = id_token.verify_oauth2_token(id_token=credentials._id_token,
                                           request=token_request,
                                           audience=GOOGLE_CLENT_ID)

    session["google_id"] = id_info.get("sub")
    session["name"] = id_info.get("name")
    return redirect(url_for("image_load"))
Пример #5
0
def authorize():
    flow.fetch_token(authorization_response=request.url)

    if not session["state"] == request.args['state']:
        abort(500)  # state does not match

    credentials = flow.credentials
    request_session = requests.session()
    cached_session = cachecontrol.CacheControl(request_session)
    token_request = google.auth.transport.requests.Request(
        session=cached_session)

    id_info = id_token.verify_oauth2_token(id_token=credentials._id_token,
                                           request=token_request,
                                           audience=google_client_id)

    session['google_id'] = id_info.get("sub")
    session["name"] = id_info.get("name")
    return redirect("/protected_area")
Пример #6
0
    async def callback():
        flow.fetch_token(authorization_response=request.url)

        if not session["state"] == request.args["state"]:
            abort(500)  # State does not match!

        credentials = flow.credentials
        request_session = requests.session()
        cached_session = cachecontrol.CacheControl(request_session)
        token_request = google.auth.transport.requests.Request(
            session=cached_session)

        id_info = id_token.verify_oauth2_token(id_token=credentials._id_token,
                                               request=token_request,
                                               audience=GOOGLE_CLIENT_ID)

        session["google_id"] = id_info.get("sub")
        session["name"] = id_info.get("name")
        session["email"] = id_info.get("email")
        session['picture'] = id_info.get('picture')

        return redirect("/protected_area")