# Authorization

1. **Authorization Request**: Your application directs the user’s browser to AIRisk’s Authorization Endpoint with your `client_id`, a `redirect_uri`, optionally a `state` string, and optionally a `userid` if you are requesting a user-specific token. If requesting a user-specific token, the `userid` must be an existing `id` on some `ApplicationUser` in the AIRisk deployment. Also,
   * `client_id` and `client_secret` must be valid for some `APIUser` in the instances database.
   * `redirect_uri` must match at least one comma-separated value in the same `APIUser`s (as the client id & secret) `redirect_uri` column
     * ![See Here](/files/fXMjcqaNq5bLjrK55wZI)
2. **Authorization Code Redirect**: If AIRisk’s authorization server authorizes the request, then it redirects the client back to the specified `redirect_uri` with an authorization code in the URL (e.g. <https://localhost/callback?code=REMOTELY\\_GENERATED\\_AUTH\\_CODE\\_HERE>). This code is short-lived and cannot be used by itself except to request a token. If `state` was provided in the initial request, then there should be a matching state parameter and value in the URL coming from the redirect  (e.g. <https://localhost/callback?state=MATCHING\\_STATE\\_VALUE\\&code=REMOTELY\\_GENERATED\\_AUTH\\_CODE\\_HERE>).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aicrisk.com/api-overview/airisk-api-oauth2-authentication/authorization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
