# Authentication

## 1. Get your ClientID and Secret <a href="#get-your-clientid-and-secret" id="get-your-clientid-and-secret"></a>

**If you are an Institution**: make sure that you have generated your ClientID and Secret for institutional use on the [Identity Service](https://identity.instructure.com/login/) page.

**If you are a Partner of Instructure**: make sure that you have received your ClientID and Secret from your Institution.

{% hint style="info" %}
Keep your ClientID and Secret in a safe place! Do not share with anyone else!
{% endhint %}

## 2. Requesting the Access Token <a href="#requesting-the-access-token" id="requesting-the-access-token"></a>

Using the ClientID and Secret you are ready to request for an `access token`. The `access token` is a JSON Web Token, that grants access to the targeted Instructure service. This is a short lived token, it needs to be renewed periodically. Typically expires in one hour.

{% openapi src="/files/gncpadGJMP8LC0N3SQxd" path="/ids/auth/login" method="post" %}
[openapi.json](https://3935729257-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FB0qnrcLHZo7GMoCVWI3W%2Fuploads%2Fgit-blob-3d8b8938ed03cf39cc60fdcfe9c001e16cd4dc5f%2Fopenapi.json?alt=media)
{% endopenapi %}

The following code snippet uses `curl` to send the request and `jq` to extract the `access token` from the answer:

```bash
ACCESS_TOKEN=$(curl --request POST https://api-gateway.instructure.com/ids/auth/login \
--user "${CLIENT_ID}:${SECRET}"  \
--data-urlencode 'grant_type=client_credentials' | jq -r '.access_token')

echo $ACCESS_TOKEN
```

## 3. Using the Access Token <a href="#example-using-the-access-token" id="example-using-the-access-token"></a>

Once you received the `access token` you can call the desired service. The example below will demonstrate this by querying the list of table names that exist in Canvas using the [DAP Query API](/services/dap/query-api/query-api-reference.md). The `access token` shall be passed as a bearer token in the Authorization header:

```bash
curl --request GET 'https://api-gateway.instructure.com/dap/query/canvas/table' \
--header "Authorization: Bearer ${ACCESS_TOKEN}" 
```

Upon success the call returns with a list of table names available Canvas.


---

# 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://developerdocs.instructure.com/services/dap/query-api/oauth_login.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.
