Package: logonlabs-python
LogonLabs PythonThe official LogonLabs Python library.DownloadFirst time installpip install logonlabs-pythonIf you have installed the package already, please upgrade it.pip install --upgrade logonlabs-pythonLogonLabs APIPrior to coding, some configuration is required athttps://app.logonlabs.com/app/#app-settingsFor the full Developer Documentation please visit:https://app.logonlabs.com/api/Instantiating a new clientYourAPP_IDcan be found inApp Settings.APP_SECRETSare configuredhere.TheLOGONLABS_API_ENDPOINTshould be set tohttps://api.logonlabs.com.Create a new instance ofLogonClient.fromlogonlabs.clientimportLogonlabslogonClient=Logonlabs('{APP_ID}','{APP_SECRETS}','{LOGONLABS_API_ENDPOINT}')SSO Login QuickStartThe StartLogin function in the JS library begins the LogonLabs managed SSO process.Further documentation on starting the login process via our JavaScript client can be found at our GitHub pagehere.
The following example demonstrates what to do once thecallback Urlhas been used by our system to redirect the user back to your page:request_headers=self.headerstoken=request_headers["token"]response=logonClient.validateLogin(token)data=response.json()ifdata['event_success']:#authentication and validation succeeded. proceed with post-auth workflows (ie, create a user session token for your system).Python Only WorkflowThe following workflow is required if you're using Python to process all transaction requests.  If this does not apply to you, please refer to the SSO Login QuickStart section.Step 1 - StartLoginThis call begins the LogonLabs managed SSO process.  Theclient_dataproperty is optional and is used to pass any data that is required after validating the request. Thetagsproperty is an Array of type Tag which is a simple object representing a key/value pair. Theforce_reauthenticationproperty is an optional method to attempt or force an Identity Provider to reauthenticate with the user.identity_provider='{string}'# one of the following ['microsoft','google','facebook','linkedin','slack','twitter','github','quickbooks','onelogin','okta','apple','basecamp','dropbox','fitbit','planningcenter','twitch']identity_provider_id='{string}'# require identity_provider or identity_provider_idclient_data='{string}'tags=[{'example-key':'example-value'}]redirect=Falsecallback_url='https://example.com'destination_url='https://example.com'force_reauthentication='{string}'# one of the following ['off', 'attempt', 'force']response=logonClient.startLogin(identity_provider,identity_provider_id,"example@emailaddress.com",client_data,callback_url,destination_url,tags,force_reauthentication)redirect_url=response.headers['Location']Theredirect_urlproperty returned should be redirected to by the application.  Upon submitting their credentials, users will be redirected to thecallback_urlset within the application settings athttps://logonlabs.com/app/#/app-settings.Step 2 - ValidateLoginThis method is used to validate the results of the login attempt.query_tokencorresponds to the query parameter with the nametokenappended to the callback url specified for your app.
The response contains all details of the login and the user has now completed the SSO workflow.  If there is any additional information to add, UpdateEvent can be called on theevent_idreturned.response=logonClient.validateLogin('{token}')data=response.json()ifdata['event_success']:#successelse:validation_details=data['validation_details']ifvalidation_details['domain_validation']=='fail':#provider used was not enabled for the domain of the user that was authenticatedifvalidation_details['ip_validation']=='fail'orvalidation_details['geo_validation']=='fail'orvalidation_details['time_validation']=='fail':#validation failed via restriction settings for the appCreateEventThe CreateEvent method allows one to create events that are outside of our SSO workflows.local_validation='{string}'# one of the following ['Pass', 'Fail', 'NotApplicable']tags=[{'example-key':'example-value'}]event_type='{string}'# one of the following ['LocalLogin', 'LocalLogout']response=logonClient.createEvent(event_type,True,local_validation,"{EMAIL_ADDRESS}","{IP_ADDRESS}","{USER_AGENT}","{FIRST_NAME}","{LAST_NAME}",tags)OAuth TokensOptionally, Identity Providers can be configured to return OAuth Tokens.  These tokens can be used to make API requests on behalf of the user by the OAuth protocol. In order to enable this featureReturn Authorization Datamust be enabled for your Provider. For more information visit theRefresh Tokens Documentation.RefreshTokenRefreshToken renews the Access Token via the Refresh Token.identityProviderId='{string}'# can be retrieved by calling GetProviderstoken='{string}'# returned by authorization_data_tokens.refresh_token in the ValidateLogin Responseresponse=logonClient.refreshToken(identityProviderId,token)refresh_token=response.authorization_data_tokens.refresh_tokenRevokeTokenRevokeToken invalidates the Token passedidentityProviderId='{string}'# can be retrieved by calling GetProviderstoken='{string}'# returned by refresh_token or access_token from authorization_data_tokens in the ValidateLogin Responseresponse=logonClient.revokeToken(identityProviderId,token)Helper MethodsGetProvidersThis method is used to retrieve a list of all providers enabled for the application.
If an email address is passed to the method, it will return the list of providers available for that email domain.response=logonClient.getProviders("example@emailaddress.com")data=response.json()social_identity_providers=data['social_identity_providers']forproviderinsocial_identity_providers:#each individual providers available for this email addressenterprise_identity_providers=data['enterprise_identity_providers']forenterpriseProviderinenterprise_identity_providers:#each enterprise providers available for this email address