コード例 #1
0
ファイル: views.py プロジェクト: sumnercreations/ENTSM
def auth_start():
    """Makes a request to Evernote for the request token then redirects the
    user to Evernote to authorize the application using the request token.

    After authorizing, the user will be redirected back to auth_finish()."""
    #CHECK SHARD INFO
    client = get_oauth_client()

    # Make the request for the temporary credentials (Request Token)
    callback_ip = "%s:%d" % (app.config.get('IP'), app.config.get('PORT'))
    callback_url = 'http://%s%s' % (callback_ip, url_for('auth_finish'))
    request_url = '%s?oauth_callback=%s' % (app.config['EN_REQUEST_TOKEN_URL'],
                                            urllib.quote(callback_url,
                                                         safe=":/"))

    resp, content = client.request(request_url, 'GET')

    if resp['status'] != '200':
        raise Exception('Invalid response %s.' % resp['status'])

    request_token = dict(urlparse.parse_qsl(content))

    # Save the request token information for later
    session['oauth_token'] = request_token['oauth_token']
    session['oauth_token_secret'] = request_token['oauth_token_secret']

    # Redirect the user to the Evernote authorization URL
    return redirect(
        '%s?oauth_token=%s' %
        (app.config['EN_AUTHORIZE_URL'], urllib.quote(session['oauth_token'])))
コード例 #2
0
ファイル: views.py プロジェクト: 3-form/ENTSM
def auth_start():
    """Makes a request to Evernote for the request token then redirects the
    user to Evernote to authorize the application using the request token.

    After authorizing, the user will be redirected back to auth_finish()."""
    #CHECK SHARD INFO
    client = get_oauth_client()

    # Make the request for the temporary credentials (Request Token)
    callback_ip = "%s:%d" %(app.config.get('IP'), app.config.get('PORT'))
    callback_url = 'http://%s%s' % (callback_ip, url_for('auth_finish'))
    request_url = '%s?oauth_callback=%s' % (app.config['EN_REQUEST_TOKEN_URL'],
        urllib.quote(callback_url, safe=":/"))

    resp, content = client.request(request_url, 'GET')

    if resp['status'] != '200':
        raise Exception('Invalid response %s.' % resp['status'])

    request_token = dict(urlparse.parse_qsl(content))

    # Save the request token information for later
    session['oauth_token'] = request_token['oauth_token']
    session['oauth_token_secret'] = request_token['oauth_token_secret']

    # Redirect the user to the Evernote authorization URL
    return redirect('%s?oauth_token=%s' % (app.config['EN_AUTHORIZE_URL'],
        urllib.quote(session['oauth_token'])))
コード例 #3
0
ファイル: views.py プロジェクト: 3-form/ENTSM
def auth_finish():
    """After the user has authorized this application on Evernote's website,
    they will be redirected back to this URL to finish the process."""

    oauth_verifier = request.args.get('oauth_verifier', '')

    token = oauth.Token(session['oauth_token'], 
                        session['oauth_token_secret'])
    token.set_verifier(oauth_verifier)

#    client = get_oauth_client()
    client = get_oauth_client(token)

    # Retrieve the token credentials (Access Token) from Evernote
    resp, content = client.request(app.config['EN_ACCESS_TOKEN_URL'], 'POST')

    if resp['status'] != '200':
        raise Exception('Invalid response %s.' % resp['status'])

    access_token = dict(urlparse.parse_qsl(content))
    authToken = access_token['oauth_token']
    
    # MAY NEED SHARD/AUTH
    userStore = get_userstore()
    user = userStore.getUser(authToken)

    # Save the users information to so we can make requests later
    session['shard_id'] = user.shardId
    session['auth_token'] = authToken
    
    # INSERT THE SESSION AND LINK TO THE USERID
    controls.update_user(session.get('username'),
                         auth_token=session.get('auth_token'), 
                         shard_id=session.get('shard_id'),
                         authorized=1)
    flash("Evernote Test Session Authorized!!")
    return redirect(url_for('index'))
コード例 #4
0
ファイル: views.py プロジェクト: sumnercreations/ENTSM
def auth_finish():
    """After the user has authorized this application on Evernote's website,
    they will be redirected back to this URL to finish the process."""

    oauth_verifier = request.args.get('oauth_verifier', '')

    token = oauth.Token(session['oauth_token'], session['oauth_token_secret'])
    token.set_verifier(oauth_verifier)

    #    client = get_oauth_client()
    client = get_oauth_client(token)

    # Retrieve the token credentials (Access Token) from Evernote
    resp, content = client.request(app.config['EN_ACCESS_TOKEN_URL'], 'POST')

    if resp['status'] != '200':
        raise Exception('Invalid response %s.' % resp['status'])

    access_token = dict(urlparse.parse_qsl(content))
    authToken = access_token['oauth_token']

    # MAY NEED SHARD/AUTH
    userStore = get_userstore()
    user = userStore.getUser(authToken)

    # Save the users information to so we can make requests later
    session['shard_id'] = user.shardId
    session['auth_token'] = authToken

    # INSERT THE SESSION AND LINK TO THE USERID
    controls.update_user(session.get('username'),
                         auth_token=session.get('auth_token'),
                         shard_id=session.get('shard_id'),
                         authorized=1)
    flash("Evernote Test Session Authorized!!")
    return redirect(url_for('index'))