Quickstart
About AuthN
AuthN allows you to build a cloud-based authentication flow to help your login, session, and user management align with your security requirements while matching the look and feel of your app.
Configuring the AuthN service
These steps are an overview of how to configure AuthN for your app. For a complete set of step-by-step instructions, refer to our configuration guide.
- Navigate to the Pangea User Console .
- Sign up to Pangea. As part of the sign-up process, an Organization and initial token will be created.
- Configure the token for use with the AuthN service. For more information, go to Get Started with AuthN.
- Set any desired settings in the AuthN Settings page.
Add AuthN to your app
The steps below will walk you through the basics of integrating our authentication tools in a Python app, including a completed code sample for getting started with user invites. For a more in-depth explanation of the sample app, you can visit our Python SDK.
Set your environment variables
Before starting to code, it is necessary to add the token and domain variables to your environment.
- Open up a bash terminal window.
- Type the following commands, replacing
yourServiceDomain
andyourAccessToken
with your Domain and Default Token copied from the AuthN page in the Pangea User Console.
export PANGEA_DOMAIN="yourServiceDomain"
export PANGEA_AUTHN_TOKEN="yourAccessToken"
Writing the AuthN code
In order to be ready to code, you must first install the Pangea SDK. Run one of the following commands in your project root directory based on your preferred choice of either Pip or Poetry.
Install SDK via Pip:
pip3 install pangea-sdk
or
Install SDK via Poetry:
poetry add pangea-sdk
- Next, import the Pangea libraries into your code.
import os
import random
import pangea.exceptions as pe
from pangea.config import PangeaConfig
from pangea.services.authn.authn import AuthN
- Define the fields for your authentication.
RANDOM_VALUE = random.randint(0, 10000000)
EMAIL_INVITE_1 = f"user.email+1{RANDOM_VALUE}@pangea.cloud" # Email to create user
EMAIL_INVITE_2 = f"user.email+2{RANDOM_VALUE}@pangea.cloud" # Email to create user
EMAIL_INVITER = f"user.email+inviter{RANDOM_VALUE}@pangea.cloud" # Email for inviting users
PASSWORD_INITIAL = "My1s+Password" # First password to be set to user created
PASSWORD_UPDATE = "My1s+Password_new" # Password used to update user password
PROFILE_INITIAL = {"name": "User Name", "country": "Argentina"} # Initial user profile
PROFILE_UPDATE = {"age": "18"} # Additional info to update user profile
- The following loads the client configuration while adding the token and domain from your environment variables so you can authenticate with Pangea. You can read more about how Pangea uses tokens on our Tokens page.
def main():
token = os.getenv("PANGEA_AUTHN_TOKEN")
domain = os.getenv("PANGEA_DOMAIN")
config = PangeaConfig(domain=domain)
authn = AuthN(token, config=config, logger_name="pangea")
- Define the parameters and request examples as shown here for a user invite.
try:
print("Inviting first user...")
response = authn.user.invite(
inviter=EMAIL_INVITER,
email=EMAIL_INVITE_1,
callback="https://www.myserver.com/callback",
state="invitestate",
)
print("Invite success. Result: ", response.result)
- Finally, check the result with error handling.
print("\nExamples run successfully")
except pe.PangeaAPIException as e:
print(f"AuthN Request Error: {e.response.summary}")
for err in e.errors:
print(f"\t{err.detail} \n")
Completed code
The code sample below is a usable, copy & paste resource for this application that will work on its own. For best results, be sure to edit placeholder data in the request with your desired values, such as the EMAIL_INVITER field.
import os
import random
import pangea.exceptions as pe
from pangea.config import PangeaConfig
from pangea.services.authn.authn import AuthN
# Generate a random value for test data
RANDOM_VALUE = random.randint(0, 10000000)
# Sample email addresses for user invitation
EMAIL_INVITE_1 = f"user.email+1{RANDOM_VALUE}@pangea.cloud" # Email for the first user
EMAIL_INVITER = f"user.email+inviter{RANDOM_VALUE}@pangea.cloud" # Email of the inviter
# Initial and updated passwords for the users
PASSWORD_INITIAL = "My1s+Password" # First password to be set for the created user
PASSWORD_UPDATE = "My1s+Password_new" # Password used to update the user's password
# Initial and updated profiles for the users
PROFILE_INITIAL = {"name": "User Name", "country": "Argentina"} # Initial user profile
PROFILE_UPDATE = {"age": "18"} # Additional info to update the user's profile
def main():
# Retrieve the authentication token and domain from environment variables
token = os.getenv("PANGEA_AUTHN_TOKEN")
domain = os.getenv("PANGEA_DOMAIN")
# Configure Pangea SDK with provided domain
config = PangeaConfig(domain=domain)
# Initialize the AuthN service with the token and configuration
authn = AuthN(token, config=config, logger_name="pangea")
try:
# Invite user
print("Inviting user...")
response = authn.user.invite(
inviter=EMAIL_INVITER,
email=EMAIL_INVITE_1,
callback="https://www.myserver.com/callback",
state="invitestate",
)
print("Invite success. Result: ", response.result)
# List invites
print("\n\nListing invites...")
response = authn.user.invites.list()
print(f"List success. {len(response.result.invites)} invites")
print("\nList result:", response.result)
print("\nExamples run successfully")
except pe.PangeaAPIException as e:
print(f"AuthN Request Error: {e.response.summary}")
for err in e.errors:
print(f"\t{err.detail} \n")
if __name__ == "__main__":
main()
Improving your app
The purpose of this guide is to provide the minimum steps required to start coding with our AuthN service, however there are additional authentication features that can be added to this process, such as adding primary and secondary authentication methods which you can read about on our Log in/Sign up flow page.
Pangea has based AuthN on years of experience building compliant enterprise applications. The service ensures that builders have what they need to build authentication flows that seamlessly fit into their applications while handling security needs.
Next steps
- Check out our Admin Guide if you have a specific task you would like to complete
- If you are feeling confident, you can browse our APIs or explore our Github repo, which has libraries for supported languages, SDKs, sample apps, etc.
- For any questions, you can connect with our Pangea Discourse for Builders or continue exploring our AuthN documentation
Was this article helpful?