Skip to content

Commit

Permalink
Making sure that we have refresh token when user logs in.
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlecat committed Jan 23, 2015
1 parent 0db762d commit 49ac8c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions critiquebrainz/frontend/login/provider.py
Expand Up @@ -93,16 +93,19 @@ def _get_auth_session():
}, decoder=json.loads)


def get_authentication_uri():
def get_authentication_uri(approval_prompt='auto'):
"""Prepare and return uri to authentication service login form.
All passed parameters should be included in a callback uri,
to which user will be redirected after a successful authentication.
Args:
approval_prompt: Either 'auto' or 'force'. Second forces approval form
display. Default is 'auto'.
"""
csrf = generate_string(20)
_persist_data(csrf=csrf)
params = {
'response_type': 'code',
'redirect_uri': url_for('login.musicbrainz_post', _external=True),
'approval_prompt': approval_prompt,
'access_type': 'offline',
'scope': 'profile rating',
'state': csrf,
Expand Down
9 changes: 7 additions & 2 deletions critiquebrainz/frontend/login/views.py
Expand Up @@ -16,15 +16,20 @@ def index():
@login_forbidden
def musicbrainz():
session['next'] = request.args.get('next')
return redirect(provider.get_authentication_uri())
force_prompt = 'force' if request.args.get('force') else 'auto'
return redirect(provider.get_authentication_uri(force_prompt))


@login_bp.route('/musicbrainz/post')
@login_forbidden
def musicbrainz_post():
"""Callback endpoint."""
if provider.validate_post_login():
login_user(provider.get_user())
user = provider.get_user()
if not user.mb_refresh_token:
# Making sure that we have refresh token for this user
return redirect(url_for('.musicbrainz', force=True))
login_user(user)
next = session.get('next')
if next:
return redirect(next)
Expand Down

0 comments on commit 49ac8c4

Please sign in to comment.