def get_access_token_util(auth_code): """ Given an auth code, retrieve and return the access token from BaseSpace """ 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) bs_api.updatePrivileges(auth_code) access_token = bs_api.getAccessToken() # set token in session var current.session.token = access_token return access_token
print "\nThe scope string for requesting read access to the reference object is:" print myReference.getAccessStr(scope='write') # We can easily request write access to the reference object so our App can start contributing analysis # by default we ask for write permission and authentication for a device accessMap = BSapi.getAccess(myReference,accessType='write') # We may limit our request to read access only if that's all that is needed readAccessMaps = BSapi.getAccess(myReference,accessType='read') print "\nWe get the following access map for the write request" print accessMap ## PAUSE HERE # Have the user visit the verification uri to grant us access print "\nPlease visit the uri within 15 seconds and grant access" print accessMap['verification_with_code_uri'] webbrowser.open_new(accessMap['verification_with_code_uri']) time.sleep(15) ## PAUSE HERE # Once the user has granted us the access to the object we requested we can # get the basespace access token and start browsing simply by calling updatePriviliges # on the baseSpaceApi instance code = accessMap['device_code'] BSapi.updatePrivileges(code) print "\nThe BaseSpaceAPI instance was update with write privileges" print BSapi # for more details on access-requests and authentication and an example of the web-based case see example 1_Authentication.py
print "\n URL for user to visit and grant access: " print deviceInfo['verification_with_code_uri'] ## PAUSE HERE # Have the user visit the verification uri to grant us access print "\nPlease visit the uri within 15 seconds and grant access" print deviceInfo['verification_with_code_uri'] webbrowser.open_new(deviceInfo['verification_with_code_uri']) time.sleep(15) ## PAUSE HERE # Once the user has granted us access to objects we requested, we can # get the basespace access token and start browsing simply by calling updatePriviliges # on the baseSpaceApi instance. code = deviceInfo['device_code'] myAPI.updatePrivileges(code) # As a reference the provided access-token can be obtained from the BaseSpaceApi object print "\nMy Access-token:" print myAPI.getAccessToken() # Let's try and grab all available genomes with our new api! allGenomes = myAPI.getAvailableGenomes() 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 = myAPI.getAccessToken() myAPI.setAccessToken(myToken) print "\nA BaseSpaceAPI instance was updated with an access-token: "
print "\n URL for user to visit and grant access: " print deviceInfo['verification_with_code_uri'] ## PAUSE HERE # Have the user visit the verification uri to grant us access print "\nPlease visit the uri within 15 seconds and grant access" print deviceInfo['verification_with_code_uri'] webbrowser.open_new(deviceInfo['verification_with_code_uri']) time.sleep(15) ## PAUSE HERE # Once the user has granted us access to objects we requested, we can # get the basespace access token and start browsing simply by calling updatePriviliges # on the baseSpaceApi instance. code = deviceInfo['device_code'] myAPI.updatePrivileges(code) # As a reference the provided access-token can be obtained from the BaseSpaceApi object print "\nMy Access-token:" print myAPI.getAccessToken() # Let's try and grab all available genomes with our new api! allGenomes = myAPI.getAvailableGenomes() 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 = myAPI.getAccessToken()