Skip to main content

API key

info

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

Untitled

Enter your credentials and press Login.

Untitled

Now just press the "Generate API Key" button

Untitled

Copy the API key and save it somewhere, you won't see it again!

Coping the API key

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:

async void CreateSessionWithAPIKey() { // Create a new session ServerSession session = new ServerSession(organization: "YOUR ORG ID"); session.SessionContext.Authenticate("YOUR API KEY"); // ... }
async void CreateSessionWithAPIKey() { // Create a new session ServerSession session = new ServerSession(organization: "YOUR ORG ID"); session.SessionContext.Authenticate("YOUR API KEY"); // ... }

Now you can register users using the ServerSession!

Developer credentials in production​

Do not include the API Key in the client build

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
API Key expiration date

Please be aware that the API keys generated with the SDK have an expiration date of one year.