def test_unauthorized_signup(remote, models_fixture): """Test unauthorized redirect on signup callback handler.""" app = models_fixture datastore = app.extensions['invenio-accounts'].datastore existing_email = '*****@*****.**' user = datastore.find_user(email=existing_email) example_response = {'access_token': 'test_access_token'} example_account_info = { 'user': { 'email': existing_email, 'external_id': '1234', 'external_method': 'test_method' } } # Mock remote app's handler current_oauthclient.signup_handlers[remote.name] = { 'info': lambda resp: example_account_info, } _security.confirmable = True _security.login_without_confirmation = False user.confirmed_at = None app.config['OAUTHCLIENT_REMOTE_APPS'][remote.name] = {} resp = authorized_signup_handler(example_response, remote) check_redirect_location(resp, lambda x: x.startswith('/login/'))
def test_unauthorized_signup(remote, models_fixture): """Test unauthorized redirect on signup callback handler.""" app = models_fixture datastore = app.extensions['invenio-accounts'].datastore existing_email = '*****@*****.**' user = datastore.find_user(email=existing_email) example_response = {'access_token': 'test_access_token'} example_account_info = {'user': { 'email': existing_email, 'external_id': '1234', 'external_method': 'test_method' }} # Mock remote app's handler current_oauthclient.signup_handlers[remote.name] = { 'info': lambda resp: example_account_info, } _security.confirmable = True _security.login_without_confirmation = False user.confirmed_at = None app.config['OAUTHCLIENT_REMOTE_APPS'][remote.name] = {} resp = authorized_signup_handler(example_response, remote) check_redirect_location(resp, lambda x: x.startswith('/login/'))
def handle_authorized(self, resp, remote, *args, **kwargs): """Handle user authorization. :param resp: User authorization response :param remote: The remote application """ from invenio_oauthclient.handlers import authorized_signup_handler return authorized_signup_handler(resp, remote, *args, **kwargs)
def authorized(resp, remote): """Authorized callback handler for GitHub.""" if resp and 'error' in resp: if resp['error'] == 'bad_verification_code': # See https://developer.github.com/v3/oauth/#bad-verification-code # which recommends starting auth flow again. return redirect(url_for('oauthclient.login', remote_app='github')) elif resp['error'] in [ 'incorrect_client_credentials', 'redirect_uri_mismatch' ]: raise OAuthResponseError("Application mis-configuration in GitHub", remote, resp) return authorized_signup_handler(resp, remote)
def authorized(resp, remote): """Authorized callback handler for GitHub.""" if resp and 'error' in resp: if resp['error'] == 'bad_verification_code': # See https://developer.github.com/v3/oauth/#bad-verification-code # which recommends starting auth flow again. return redirect(url_for('oauthclient.login', remote_app='github')) elif resp['error'] in ['incorrect_client_credentials', 'redirect_uri_mismatch']: raise OAuthResponseError( "Application mis-configuration in GitHub", remote, resp ) return authorized_signup_handler(resp, remote)
def test_authorized_signup_handler(remote, models_fixture): """Test authorized signup handler.""" datastore = models_fixture.extensions['invenio-accounts'].datastore user = datastore.find_user(email='*****@*****.**') example_response = {'access_token': 'test_access_token'} # Mock remote app's handler current_oauthclient.signup_handlers[remote.name] = { 'setup': lambda token, resp: None } # Authenticate user oauth_authenticate('dev', user) # Mock next url next_url = '/test/redirect' session[token_session_key(remote.name) + '_next_url'] = next_url # Check user is redirected to next_url resp = authorized_signup_handler(example_response, remote) check_redirect_location(resp, next_url)