OpenID Login
Users can sign in with an account they already have at an OpenID provider, such as Google, instead of a password for your project.
How it works
- The project owner registers an OpenID logger in the project settings on skapi.com. It tells Skapi which URL returns the user's profile for a token, and which profile attribute is the user's unique username. Each logger has an ID, for example
google. - Your app gets an access token from the provider, the way the provider documents it.
open_id_login()sends the token and the logger ID. Skapi asks the provider for the profile, then signs the user in, creating the account on first use.
from skapi import Skapi, SkapiError
skapi = Skapi("<Project ID>")
res = skapi.open_id_login(access_token, "google")
print(res["userProfile"]["user_id"])
print(res["openid"]) # the profile attributes the provider returnedIt returns a dict with userProfile (the user's profile) and openid (the attributes from the provider).
If the account has two-step login on, open_id_login() raises MFA_REQUIRED and verify_mfa() finishes the login.
To send one of your project's uploaded templates as the welcome e-mail for a new account, pass template={"welcome": "<message_id>"}.
Merging with an existing account
If the user already signed up with a password using the same login ID, open_id_login() raises ACCOUNT_EXISTS. The user can merge the OpenID login into that account with merge:
merge=Truemerges the accounts and copies no attributes.merge=["name"]merges and also copies the listed OpenID attributes into the profile.
try:
res = skapi.open_id_login(access_token, "google")
except SkapiError as err:
if err.code != "ACCOUNT_EXISTS":
raise
if input("An account already exists. Merge? (y/n) ") == "y":
res = skapi.open_id_login(access_token, "google", merge=True)DANGER
After a merge, the user can no longer log in with a password. This cannot be undone.
An existing account that has not confirmed its signup yet cannot be merged: open_id_login() raises INVALID_REQUEST (The account needs to be confirmed.).
