API key
Only available from version v2.0.0 onwards.
Sometimes you will need a higher permissions to perform certain actions within the SDK. Those times you will need to use an API Key.
Generating the API Key​
Go to the Project Setup window Top Bar -> Union Avatars -> Project Setup
Enter your credentials and press Login.
Now just press the "Generate API Key" button
Copy the API key and save it somewhere, you won't see it again!
If you can't copy the key from the setup window, check the Unity Editor Log, it's there too
--
Using the API Key​
In order to use the API Key we just need to pass it to the SessionContext inside of our ISession. For that we have a method called Authenticate which accepts a string (API Key) as a parameter.
It should look like this:
csharp
async void CreateSessionWithAPIKey(){// Create a new sessionServerSession session = new ServerSession(organization: "YOUR ORG ID");session.SessionContext.AuthenticateWithApiKey("YOUR API KEY");// ...}
csharp
async void CreateSessionWithAPIKey(){// Create a new sessionServerSession session = new ServerSession(organization: "YOUR ORG ID");session.SessionContext.AuthenticateWithApiKey("YOUR API KEY");// ...}
Now you can register users using the ServerSession!
Developer credentials in production​
Doing this is a major risk and can expose your credentials to everyone
While it may not be a problem for development demos, you won't want to include your credentials in your publicly available build. That's why you will need to setup a server-client solution to perform operations that require an API key. The approach to provide the API key to your client build can vary from each project, but here's an example:
- Server starts and initializes an ISession with the API Key
- Client wants to register a new user so sends request to a server
- Server handles the request, creates the user and returns the result to client
Please be aware that the API keys generated with the SDK have an expiration date of one year.