def googledrive_oauth_start(auth, **kwargs): """View function that does OAuth Authorization and returns access token""" # Run through the OAuth flow and retrieve credentials # Store the node ID on the session in order to get the correct redirect URL # upon finishing the flow user = auth.user nid = kwargs.get('nid') or kwargs.get('pid') node = models.Node.load(nid) if nid else None node_addon = user.get_addon('googledrive') # Fail if node provided and user not contributor if node and not node.is_contributor(user): raise HTTPError(http.FORBIDDEN) # Handle if user has already authorized google drive if node_addon and node_addon.has_auth: return redirect(web_url_for('user_addons')) client = GoogleAuthClient() authorization_url, state = client.start() session.data['googledrive_auth_state'] = state if nid: session.data['googledrive_auth_nid'] = nid return redirect(authorization_url)