コード例 #1
0
def oauth_callback():
    code = request.args.get("code", None)
    if not code:
        logging.error("No code, no authorization")
        abort(500)
    redirect_uri = helpers.url_for("oauth_callback", _external=True)
    oauth_helper = OAuthDanceHelper(redirect_uri=redirect_uri)
    credentials = oauth_helper.step2_exchange(code)
    client = Client.get_by_id(1)
    if not client:
        logging.error("No client object, aborting authorization")
        abort(500)
    client.credentials = credentials.to_json()
    if credentials.refresh_token:
        client.refresh_token = credentials.refresh_token
    client.put()

    return redirect(helpers.url_for("settings"))
コード例 #2
0
ファイル: admin_views.py プロジェクト: dcifuen/gentlemeet
 def start_oauth2_dance(self):
     login_hint = ''
     scope = ''
     client = Client.get_by_id(1)
     if not client:
         # If client does not exist then create an empty one
         client = Client(id=1)
         client.installer_user = users.get_current_user().email()
         client.put()
     # Get the login hint from configuration
     approval_prompt = 'auto' if client.refresh_token else 'force'
     scope = constants.OAUTH2_SCOPE
     redirect_uri = helpers.url_for('oauth.oauth_callback',
                                    _external=True)
     oauth_helper = OAuthDanceHelper(redirect_uri, approval_prompt, scope)
     url = oauth_helper.step1_get_authorize_url()
     #TODO: Add a random token to avoid forgery
     return redirect(url)
コード例 #3
0
def start_oauth2_dance():
    login_hint = ""
    scope = ""
    client = Client.get_by_id(1)
    if not client:
        # If client does not exist then create an empty one
        client = Client(id=1)
        client.put()
    # Get the login hint from configuration

    # approval_prompt = 'auto' if client.reseller_refresh_token else 'force'
    # Always force to be sure to get valid refresh token
    approval_prompt = "force"
    login_hint = get_setting("OAUTH2_RESELLER_DOMAIN_USER")
    scope = get_setting("OAUTH2_SCOPE")
    redirect_uri = helpers.url_for("oauth_callback", _external=True)
    oauth_helper = OAuthDanceHelper(scope=scope, redirect_uri=redirect_uri, approval_prompt=approval_prompt)
    url = oauth_helper.step1_get_authorize_url()
    # TODO: Add a random token to avoid forgery
    return redirect("%s&login_hint=%s" % (url, login_hint))
コード例 #4
0
ファイル: views.py プロジェクト: Eforcers/inbox-cleaner
def start_oauth2_dance(domain):
    current_user = users.get_current_user()
    user_email = current_user.email()
    login_hint = user_email
    user_domain = current_user.email().split('@')[1]

    if user_domain != domain:
        domain = user_domain

    primary_domain = PrimaryDomain.get_or_create(domain)
    approval_prompt = 'auto' if primary_domain.refresh_token else 'force'
    scope = constants.OAUTH2_SCOPES
    state = urllib.quote(domain)

    redirect_uri = url_for('oauth_callback', _external=True)
    oauth_helper = OAuthDanceHelper(scope=scope, redirect_uri=redirect_uri,
                                    approval_prompt=approval_prompt)
    url = oauth_helper.step1_get_authorize_url()
    # TODO: Add a random token to avoid forgery
    return redirect("%s&state=%s&login_hint=%s" % (url, state, login_hint))
コード例 #5
0
ファイル: admin_views.py プロジェクト: dcifuen/gentlemeet
 def oauth_callback(self):
     code = request.args.get('code', None)
     if code:
         redirect_uri = helpers.url_for('oauth.oauth_callback',
                                        _external=True)
         oauth_helper = OAuthDanceHelper(redirect_uri)
         credentials = oauth_helper.step2_exchange(code)
         client = Client.get_by_id(1)
         if client:
             client.credentials = credentials.to_json()
             if credentials.refresh_token:
                 client.refresh_token = credentials.refresh_token
             client.put()
             return redirect(helpers.url_for('oauth.index'))
         else:
             logging.error('No client object, aborting authorization')
             abort(500)
     else:
         logging.error('No code, no authorization')
         abort(500)
コード例 #6
0
ファイル: views.py プロジェクト: Eforcers/inbox-cleaner
def oauth_callback():
    code = request.args.get('code', None)
    if not code:
        logging.error('No code, no authorization')
        abort(500)
    state = request.args.get('state', None)
    if not state:
        logging.error('No state, no authorization')
        abort(500)
    domain_name = urllib.unquote(state)

    redirect_uri = url_for('oauth_callback', _external=True)
    oauth_helper = OAuthDanceHelper(redirect_uri=redirect_uri)
    credentials = oauth_helper.step2_exchange(code)

    primary_domain = PrimaryDomain.get_or_create(domain_name)
    primary_domain.credentials = credentials.to_json()
    if credentials.refresh_token:
        primary_domain.refresh_token = credentials.refresh_token
    user = users.get_current_user()
    primary_domain.admin_email = user.email()
    primary_domain.put()

    return redirect(url_for('settings'))