def test_oauthsignin_get_provider(self): from app import app, OAuthSignIn, GoogleSignIn app.config['SERVER_NAME'] = 'localhost:8000' with app.app_context(): oauthsignin = OAuthSignIn.get_provider('google') googlesignin = GoogleSignIn() self.assertEqual(oauthsignin.__class__, googlesignin.__class__)
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('main.index')) oauth = OAuthSignIn.get_provider(provider) social_id, username, email = oauth.callback() if social_id is None: flash('Authentication failed.') return redirect(url_for('main.index')) user = User.query.filter_by(social_id=social_id).first() if not user: user = User(social_id=social_id, nickname=username, email=email) db.session.add(user) db.session.commit() login_user(user, True) return redirect(url_for('main.index'))
def oauth_callback(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth_obj = OAuthSignIn.get_provider(provider) social_id, username, email, alt_email_str = oauth_obj.callback() if social_id is None: flash('Authentication failed.', 'error') return redirect(url_for('index')) user = User.query.filter_by(social_id=social_id).first() modified = False # CREATE NEW USER IF NOT IN DB if not user: if social_id in g.members_dict: email = g.members_dict[social_id] user = User(social_id=social_id, display_name=username, email=email, alt_email_str=alt_email_str) modified = True use_name = user.get_official_name() # UPDATE EMAIL DATA IF NECESSARY if user.email != email or user.alt_email_str != alt_email_str \ or user.use_name != use_name: user.email = email user.alt_email_str = alt_email_str user.use_name = use_name modified = True # GET ASANA IDS IF MATCH PRESENT if user.asana_id is None: asana_id = get_asana_id_for_user(user) if asana_id: user.asana_id = asana_id modified = True if modified: db.session.add(user) db.session.commit() login_user(user, True) return redirect(url_for('index'))
def oauth_authorize(provider): if not current_user.is_anonymous: return redirect(url_for('index')) oauth_obj = OAuthSignIn.get_provider(provider) return oauth_obj.authorize()
def test_googlesignin_authorize(self): from app import app, OAuthSignIn app.config['SERVER_NAME'] = 'localhost:8000' with app.app_context(): oauth = OAuthSignIn.get_provider('google') self.assertEqual(oauth.authorize().status_code, 302)
def test_oauthsignin_get_callback_url(self): from app import app, OAuthSignIn app.config['SERVER_NAME'] = 'localhost:8000' with app.app_context(): self.assertEqual(OAuthSignIn.get_callback_url(), 'https://localhost:8000/oauth2callback')