0
0
Flaskframework~10 mins

OAuth2 overview in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Flask-OAuthlib client.

Flask
from flask_oauthlib.client import [1]
Drag options to blanks, or click blank then click option'
AOAuth
BOAuth2
COAuthClient
DOAuthProvider
Attempts:
3 left
💡 Hint
Common Mistakes
Using OAuth2 instead of OAuth
Using OAuthClient which does not exist
2fill in blank
medium

Complete the code to create an OAuth object in a Flask app.

Flask
oauth = [1](app)
Drag options to blanks, or click blank then click option'
AOAuthProvider
BOAuth2
COAuth
DOAuthClient
Attempts:
3 left
💡 Hint
Common Mistakes
Using OAuth2 which is not the class name
Using OAuthProvider which is for servers
3fill in blank
hard

Fix the error in the OAuth remote app registration code.

Flask
google = oauth.remote_app(
    'google',
    consumer_key='[1]',
    consumer_secret='YOUR_SECRET',
    request_token_params={'scope': 'email'},
    base_url='https://www.googleapis.com/oauth2/v1/',
    request_token_url=None,
    access_token_method='POST',
    access_token_url='https://accounts.google.com/o/oauth2/token',
    authorize_url='https://accounts.google.com/o/oauth2/auth'
)
Drag options to blanks, or click blank then click option'
AGOOGLE_CLIENT_ID
BGOOGLE_SECRET
CCLIENT_ID
DAPI_KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using the secret instead of the client ID
Using API_KEY which is unrelated
4fill in blank
hard

Fill both blanks to complete the OAuth token getter function.

Flask
@google.tokengetter
def get_google_oauth_token():
    return [1].get('access_token'), [2]
Drag options to blanks, or click blank then click option'
Asession
BNone
Crequest
Dcurrent_user
Attempts:
3 left
💡 Hint
Common Mistakes
Returning request instead of session
Returning current_user which is unrelated
5fill in blank
hard

Fill all three blanks to complete the OAuth login route using Flask.

Flask
@app.route('/login')
def login():
    return [1].authorize(callback=[2]('authorized', _external=True))

@app.route('/login/authorized')
def authorized():
    resp = [3].authorized_response()
    if resp is None or resp.get('access_token') is None:
        return 'Access denied.'
    session['access_token'] = resp['access_token']
    return 'You are logged in!'
Drag options to blanks, or click blank then click option'
Agoogle
Burl_for
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Using redirect instead of google.authorize
Not using url_for for callback URL