> ## Documentation Index
> Fetch the complete documentation index at: https://docs.msu.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Authorization Code Request

> Redirect the user to authenticate and obtain an Authorization Code.

Redirects the user's browser to authenticate and grant permissions. On success, issues a one-time Authorization Code to the registered `redirect_uri`.

## Query parameters

<ParamField query="client_id" type="string" required>
  Unique client identifier issued during app registration.
</ParamField>

<ParamField query="redirect_uri" type="string" required>
  Callback URL to receive the Authorization Code. Must exactly match the URI registered with the OAuth client.
</ParamField>

<ParamField query="response_type" type="string" required>
  Must be fixed value `code`.
</ParamField>

<ParamField query="state" type="string">
  Recommended. Random unique string for CSRF protection. Returned as-is in the redirect callback.
</ParamField>

<ParamField query="code_challenge" type="string">
  PKCE code challenge (43–128 chars). Required if `code_challenge_method` is provided.
</ParamField>

<ParamField query="code_challenge_method" type="string">
  PKCE method (`plain` or `S256`). Required if `code_challenge` is provided.
</ParamField>

## Response

On success, the user's browser is redirected to the `redirect_uri` with the Authorization Code. On error, the browser is redirected to an error page.

<ResponseField name="code" type="string">
  One-time Authorization Code. Pass this to `POST /oauth/token` to obtain tokens.
</ResponseField>

<ResponseField name="state" type="string">
  Echoed back from the request. Use this to verify the response integrity.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request GET \
    --url 'https://oauth.msu.io/oauth/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&response_type=code&state={STATE}'
  ```

  ```javascript JavaScript theme={null}
  const params = new URLSearchParams({
    client_id: '{CLIENT_ID}',
    redirect_uri: '{REDIRECT_URI}',
    response_type: 'code',
    state: '{STATE}'
  });
  window.location.href = `https://oauth.msu.io/oauth/authorize?${params}`;
  ```

  ```python Python theme={null}
  import urllib.parse

  params = urllib.parse.urlencode({
    "client_id": "{CLIENT_ID}",
    "redirect_uri": "{REDIRECT_URI}",
    "response_type": "code",
    "state": "{STATE}"
  })
  redirect_url = f"https://oauth.msu.io/oauth/authorize?{params}"
  ```
</RequestExample>

<ResponseExample>
  ```http Response theme={null}
  HTTP/1.1 302 Found
  Location: {REDIRECT_URI}?code={AUTHORIZATION_CODE}&state={STATE}
  ```
</ResponseExample>
