Auth
Introduction
NSDK provides AuthN/AuthZ in different ways depending on where you are at in the development lifecycle:
- Developers that just want to try out our features with the samples will use the Niantic Spatial Identity Service to Authenticate and Authorize their usage (i.e. use the same credentials as what is used to log in to scaniverse.nianticspatial.com).
- When a developer wants to do a proof of concept, they can continue to use their portal credentials in their own application.
- Finally, when a developer is ready to build a production application, they can combine their own identity and identity service with our authorization platform.
See the table below for a summary of this information.
| Development Stage | Auth Solution |
|---|---|
| Initial Evaluation | Create an account and login on entry to the sample app |
| Proof Of Concept | Reuse the sample login flow in your application |
| Production Application | Combine your own identity service with our authorization platform |
Trying out NSDK For the First Time
NSDK comes with sample applications for Swift, Kotlin, and Unity. Some features in these samples require authN/authZ to work.
To try these out, you will need to:
- Register an account at https://portal-web.nianticspatial.com/signin
- Login on entry to the sample application.
Under the hood, the sample applications use the Niantic Spatial Identity Service to authenticate and authorize your usage:
- Successfully logging in returns a user session refresh token
- This token is used to remain logged into the sample, but is also used to obtain a Niantic Spatial API refresh token.
- The Niantic Spatial refresh token that is plugged into the NSDK, where it is used internally to get access tokens.
Trying Out NSDK With Your Own Application
To use NSDK in a production application, you will eventually need to set up a backend service. But for initial proof of concept, the login flow in the sample can be copied to an application written in Swift, Kotlin, or Unity.
The exact implementation details will depend on the platform you are using. In Swift and Kotlin, the Auth folder of the sample application contains the code that you will need to copy. The important files (in Swift or Kotlin) are as follows:
| File Name | Description |
|---|---|
| LoginManager | Opens the web-page for login into the Enterprise Auth sample and receives the results |
| UserSessionManager | Maintains a user session while the app is running |
| RequestRuntimeRefreshToken | Converts a user session token into a Niantic Spatial refresh token |
How to build an app with your own users
The Niantic Spatial Identity Service is intended to be combined with your own identity service. When your users have logged in, you will need to do the following:
- Request a Niantic Spatial access token.
- Plug the access token into the NSDK.
- Periodically check to see if the access token is about to expire.
- If it is about to expire, request a new access token and repeat.
Requesting Niantic Spatial access tokens directly requires a service account and an API key. For security, these should be kept on your back end server, along with access token request logic. Service accounts can be created at https://portal-web.nianticspatial.com/, and from there you can generate an API key.