def get_auth_code_util(scope): """ Initiate OAuth2 to get auth code for the given scope, returns url to redirect to so user can confirm scope via oauth2 dialog """ if not scope: scope = "" app = current.db(current.db.app_data.id > 0).select().first() bs_api = BaseSpaceAPI(app.client_id,app.client_secret,app.baseSpaceUrl,app.version, current.session.app_session_num) url = bs_api.getWebVerificationCode(scope,app.redirect_uri) return url
# object using the key-word AccessToken. myToken = myAPI.getAccessToken() myAPI.setAccessToken(myToken) print "\nA BaseSpaceAPI instance was updated with an access-token: " print myAPI #################### Web-based verification ################################# # The scenario where the authentication is done through a web-browser if clientKey: BSapiWeb = BaseSpaceAPI(clientKey, clientSecret, apiServer, apiVersion, appSessionId) else: BSapiWeb = BaseSpaceAPI(profile='DEFAULT') userUrl = BSapiWeb.getWebVerificationCode('browse global', 'http://localhost', state='myState') print "\nHave the user visit:" print userUrl webbrowser.open_new(userUrl) # Once the grant has been given you will be redirected to a url looking something like this # http://localhost/?code=<MY DEVICE CODE FROM REDICRECT>&state=myState&action=oauthv2authorization # By getting the code parameter from the above http request we can now get our access-token myCode = '<MY DEVICE CODE FROM REDIRECT>' #BSapiWeb.updatePrivileges(myCode) #################### Storing BaseSpaceApi using python's pickle module #################################
print "\nGenomes \n" + str(allGenomes) # If at a later stage we wish to initialize a BaseSpaceAPI object when we already have # an access-token from a previous sessions, this may simply be done by initializing the BaseSpaceAPI # object using the key-word AccessToken. myToken = BSapi.getAccessToken() BSapi = BaseSpaceAPI(client_key, client_secret, BaseSpaceUrl, version, AppSessionId, AccessToken=myToken) print "\nA BaseSpaceAPI instance initialized with an access-token: " print BSapi #################### Web-based verification ################################# # The scenario where the authentication is done through a web-browser BSapiWeb = BaseSpaceAPI(client_key, client_secret, BaseSpaceUrl, version, AppSessionId) userUrl= BSapiWeb.getWebVerificationCode('browse global','http://localhost',state='myState') print "\nHave the user visit:" print userUrl webbrowser.open_new(userUrl) # Once the grant has been given you will be redirected to a url looking something like this # http://localhost/?code=<MY DEVICE CODE FROM REDICRECT>&state=myState&action=oauthv2authorization # By getting the code parameter from the above http request we can now get our access-token myCode = '<MY DEVICE CODE FROM REDICRECT>' #BSapiWeb.updatePrivileges(myCode) #################### Storing BaseSpaceApi using python's pickle module #################################