Kotlin & Django Quickstart
This is a quickstart guide to help you integrate Descope with your Kotlin & Django application. Follow the steps below to get started.
Add the Descope Package
Next, we need to add the Descope Kotlin SDK as a dependency.
- Within Android Studio, go to File > Project Structure > Dependencies > Add Dependency > Library Dependency
- Search for the dependency: "com.descope"
- Configure your desired dependency rules
- Click "Ok"
Import the Kotlin SDK
Next step is to import the Descope Kotlin dependency
Configure Descope with a custom Project ID
Configure Descope in the MainActivity
class. A Descope Project ID is required to initialize the SDK. You can find this ID on the project page in the Descope Console.
Note
You can also add the optional baseUrl
parameter if you're utilizing a CNAME within your Descope project (ex: https://auth.company.com
).
Define and host your flow
Before we can run a flow, it must first be defined and hosted. Every project comes with predefined flows out of the box, found in your Descope console. You can customize your flows to suit your needs and host it. Essentially, you'll need the URL where your authentication flow is separately hosted on the web (eg. https://example.com/login
).
Run your Flow
After completing the prerequisite steps, it is now possible to run a flow.
The flow will run in a dedicated DescopeFlowView
which receives
a DescopeFlow
object. The DescopeFlow
objects defines all of the options available when running a flow.
Read the class documentation for a detailed explanation.
The flow needs to reside in your UI in some form, and to start it, call the run()
function
Note
If you need to support Magic Link redirects, follow the steps in our README.
Utilize the Kotlin SDK Session Management Functions
Descope provides the sessionManager to check if the user is authenticated or get user data such as email, userId, etc. You can use these to customize the user experience:
isAuthenticated
- is user authenticated?user
- user object that contains all user attributes (email, name, etc.)me
- updates the managed session user details and returns itlogout
- logs the user out by revoking the active session and clearing it from the session manager storage
At this point, you're done with the frontend. If you'd like more detail into frontend Session Management, check out our SDK. If you would like to also handle Session Validation in your backend, keep on reading!
Install Backend SDK
Install the SDK with the following command:
Import and Setup Backend SDK
You'll need install and setup all of the packages from the SDK. This is done by ensuring django_descope
is under INSTALLED_APPS
in settings.py
.
If you're using a CNAME with your Descope project, make sure to export the Base URL (e.g. export DESCOPE_BASE_URI="https://api.descope.com"
) when initializing descope_client
.
Add Descope Middleware
Ensure Descope Middleware is after the AuthenticationMiddleware and SessionMiddleware.
Configure URLconf
You will then need to include the Descope URLconf in your project urls.py
like this.
Configure URLconf
The session validation is handled in the Django SDK, through the middleware.
Congratulations
Now that you've got the authentication down, go focus on building out the rest of your app!
Here is a sample application using the Django SDK.
Checkpoint
Your application is now integrated with Descope. Please test with sign-up or sign-in use case.
Customize
Now that you have the end-to-end application working, you can choose to configure and personalize many different areas of Descope, including your brand, style, custom user authentication journeys, etc. We recommend starting with customizing your user-facing screens, such as signup and login.