# Authorization Endpoint

**Endpoint:** `GET /api/oauth2`

**Purpose:** Initiate an OAuth2 authorization code request (user login & consent).

**Query Parameters**:

* `client_id` (string, <mark style="color:red;">Required</mark>)
  * &#x20;Your application’s client identifier. This value is provided when you register your app with AIRisk. It tells the authorization server which application is making the request.
* `redirect_uri` (string, <mark style="color:red;">Required</mark>)
  * &#x20;The URL in your application where users will be sent after authorization. This must match one of the allowed redirect URIs you configured for your client. After the user approves or denies the request, AIRisk will redirect their browser to this URL with additional parameters (code or error).
* `state` (string, <mark style="color:orange;">Optional</mark>)
  * A string locally generated and stored to use to prevent CSRF attacks. The value of this parameter must be stored and compared with the `state` parameter value existing alongside `code` in the response once having been redirected to the passed `redirect_uri`. The stored value must match the value retrieved from the response parameters. See [this official oauth2 documentation](https://auth0.com/docs/secure/attack-protection/state-parameters) for more information on this convention.
* `userid` (string, <mark style="color:orange;">Optional</mark>)
  * &#x20;An identifier for the user on whose behalf the authorization is being requested. Include this if you want a user-specific token. When provided, the authorization process will associate the resulting code with the specified user. If omitted, the authorization is not tied to a specific user and will result in a generic token (suitable for application-level access).


---

# 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-endpoint.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.
