Skip to content

Commit 17c45e5

Browse files
am-steadCopilotfelicitymay
authored
[EDI - Builders] - Copilot Extensions "How-Tos" ("Using OIDC with Copilot Extensions") #5523 (#56522)
Co-authored-by: Copilot <[email protected]> Co-authored-by: Felicity Chapman <[email protected]>
1 parent 756f0da commit 17c45e5

File tree

5 files changed

+200
-176
lines changed

5 files changed

+200
-176
lines changed

content/copilot/concepts/build-copilot-extensions/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ children:
1010
- /about-building-copilot-extensions
1111
- /agents-for-copilot-extensions
1212
- /skillsets-for-copilot-extensions
13+
- /openid-connect
1314
---
1415

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: OpenID Connect (OIDC) for Copilot Extensions
3+
intro: 'Learn how OpenID Connect (OIDC) enables {% data variables.copilot.copilot_extensions_short %} to securely authenticate users and access cloud resources without storing long-lived credentials.'
4+
versions:
5+
feature: copilot-extensions
6+
topics:
7+
- Copilot
8+
shortTitle: OpenID Connect
9+
allowTitleToDifferFromFilename: true
10+
type: overview
11+
---
12+
13+
## About OpenID Connect (OIDC) for {% data variables.copilot.copilot_extensions_short %}
14+
15+
OpenID Connect (OIDC) allows {% data variables.copilot.copilot_extensions_short %} to exchange short-lived tokens directly from their cloud provider instead of storing long-lived {% data variables.product.github %} credentials. This feature enables both Copilot agents and skillsets to more securely authenticate users and access cloud resources.
16+
17+
### Overview of OIDC
18+
19+
{% data variables.copilot.copilot_extensions_short %} often need to access third-party resources or APIs on behalf of users. Traditionally, this required storing {% data variables.product.github %} tokens as secrets and making additional API calls to map these tokens to user identities in your system. With OIDC, your extension can request short-lived access tokens directly from your authentication service by exchanging {% data variables.product.github %} identity information.
20+
21+
When enabled, {% data variables.product.github %}'s OIDC provider automatically generates a token containing claims about the user and the request context. Your authentication service can validate these claims and exchange them for an access token scoped specifically for your service.
22+
23+
Using OIDC is especially valuable for {% data variables.product.prodname_copilot_short %} skillsets development because it allows you to leverage your existing API endpoints without maintaining separate {% data variables.product.github %}-specific endpoints. Instead of duplicating endpoints to accept {% data variables.product.github %} tokens, you can use OIDC to translate {% data variables.product.github %} identities into your service’s native authentication tokens.
24+
25+
### Benefits of using OIDC
26+
27+
By implementing OIDC token exchange in your {% data variables.copilot.copilot_extension_short %}, you can:
28+
29+
* Avoid storing long-lived {% data variables.product.github %} tokens or maintain a mapping between {% data variables.product.github %} and your service's identities.
30+
* Use short-lived tokens that automatically expire and can be scoped specifically to your service's needs.
31+
* Avoid making additional calls to {% data variables.product.github %}'s API to validate tokens and fetch user information.
32+
* Enable direct integration for {% data variables.product.prodname_copilot_short %} Skills with your existing APIs without maintaining separate endpoints for {% data variables.product.github %}.
33+
* Reuse existing API endpoints by translating {% data variables.product.github %} authentication into your service's native tokens.
34+
35+
## About token exchange flow
36+
37+
The following outlines how the {% data variables.copilot.copilot_extensibility_platform_short %} exchanges an OIDC token for an access token to authenticate requests to your extension.
38+
39+
### Initial request
40+
41+
1. The user sends a message to your {% data variables.copilot.copilot_extension_short %}.
42+
1. GitHub generates an OIDC token containing user identity information.
43+
1. GitHub calls your token exchange endpoint with the OIDC token.
44+
1. Your service validates the token and returns an access token.
45+
1. GitHub includes your access token in the request to your extension.
46+
47+
```http request
48+
# HTTP header
49+
Authorization: Bearer <your-service-token>
50+
X-GitHub-Token: <github-token>
51+
```
52+
53+
### Subsequent requests
54+
55+
1. {% data variables.product.github %} caches your access token for up to 10 minutes.
56+
1. The cached token is reused for subsequent requests.
57+
1. If the token expires or becomes invalid, {% data variables.product.github %} requests a new one.
58+
59+
## Understanding OIDC tokens
60+
61+
The OIDC token from {% data variables.product.github %} is a JWT containing claims about the user and request context:
62+
63+
```json
64+
{
65+
"jti": "<unique-token-id>",
66+
"sub": "<github-user-id>",
67+
"aud": "<your-client-id>",
68+
"iss": "https://github.com/login/oauth",
69+
"nbf": 1632492967,
70+
"exp": 1632493867,
71+
"iat": 1632493567,
72+
"act": {
73+
"sub": "api.copilotchat.com"
74+
}
75+
}
76+
```
77+
78+
## Best practices
79+
80+
* Scope tokens to the minimum required permissions.
81+
* Implement proper error handling and logging.
82+
* Monitor token exchange patterns for security anomalies.
83+
* Keep tokens short-lived to minimize security risks.
84+
* Validate all claims before issuing access tokens.
85+
* Consider implementing rate limiting on your token exchange endpoint.
86+
* Use HTTPS for all token exchange communications.
87+
88+
## Next steps
89+
90+
* [AUTOTITLE](/copilot/how-tos/build-copilot-extensions/set-up-oidc)

content/copilot/how-tos/build-copilot-extensions/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ children:
1111
- /creating-a-copilot-extension
1212
- /building-a-copilot-agent-for-your-copilot-extension
1313
- /building-a-copilot-skillset-for-your-copilot-extension
14-
- /using-oidc-with-github-copilot-extensions
14+
- /set-up-oidc
1515
- /debugging-your-github-copilot-extension
1616
- /managing-the-availability-of-your-copilot-extension
1717
redirect_from:
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
title: Setting up OIDC for your GitHub Copilot extension
3+
intro: 'Learn how to set up OpenID Connect (OIDC) with your {% data variables.copilot.copilot_extension_short %} to enhance security.'
4+
versions:
5+
feature: copilot-extensions
6+
topics:
7+
- Copilot
8+
shortTitle: Set up OIDC
9+
type: how_to
10+
allowTitleToDifferFromFilename: true
11+
redirect_from:
12+
- /copilot/building-copilot-extensions/using-oidc-with-copilot-extensions
13+
- /copilot/building-copilot-extensions/using-oidc-with-github-copilot-extensions
14+
- /copilot/how-tos/build-copilot-extensions/using-oidc-with-github-copilot-extensions
15+
---
16+
17+
## Introduction
18+
19+
You can set up OIDC so that {% data variables.product.prodname_copilot_short %} agents and skillsets can more securely authenticate users and access cloud resources. For more information on OIDC, see [AUTOTITLE](/copilot/concepts/build-copilot-extensions/openid-connect).
20+
21+
There are three steps to setting up OIDC for your extension.
22+
* [Configure your token exchange endpoint](#configure-your-token-exchange-endpoint).
23+
* [Enable OIDC in your Copilot extensions settings](#enable-oidc-in-your-copilot-extensions-settings).
24+
* [Validate OIDC tokens](#validate-oidc-tokens).
25+
26+
## Configure your token exchange endpoint
27+
28+
Create an endpoint in your service that conforms to the [RFC 8693 OAuth 2.0 Token Exchange](https://www.rfc-editor.org/rfc/rfc8693.html).
29+
This endpoint should:
30+
* Accept `POST` requests with the following form-encoded parameters:
31+
32+
```http request
33+
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
34+
&resource=<https://your-service.com/resource>
35+
&subject_token=<github-jwt-token>
36+
&subject_token_type=urn:ietf:params:oauth:token-type:id_token
37+
```
38+
39+
* Return a JSON response with your service's access token:
40+
41+
```json
42+
{
43+
"access_token": <"your-service-token">,
44+
"issued_token_type":"urn:ietf:params:oauth:token-type:access_token",
45+
"token_type": "Bearer",
46+
"expires_in": 3600
47+
}
48+
```
49+
50+
* Return an error response when validation fails:
51+
52+
```json
53+
{
54+
"error": "invalid_request"
55+
}
56+
```
57+
58+
## Enable OIDC in your {% data variables.copilot.copilot_extension_short %}'s settings
59+
60+
In your {% data variables.copilot.copilot_extension_short %}'s configuration, enable OIDC:
61+
62+
{% data reusables.apps.settings-step %}
63+
{% data reusables.apps.enterprise-apps-steps %}
64+
1. To the right of the {% data variables.product.prodname_github_app %} you want to configure for your {% data variables.copilot.copilot_extension_short %}, click **Edit**.
65+
1. In the left sidebar, click **{% data variables.product.prodname_copilot_short %}**.
66+
1. Under **OpenID Connect Token Exchange**, check **Enabled**.
67+
1. In the **Token exchange endpoint** field, input your token exchange URL.
68+
1. In the **Request header key** field, input the header key for your service's token. The default is `Authorization`.
69+
1. In the **Request header value** field, input the header value format. The default is `Bearer ${token}`.
70+
71+
## Validate OIDC tokens
72+
73+
Your token exchange endpoint should validate the {% data variables.product.github %} OIDC token by following the steps below:
74+
1. Fetch the JSON Web Key Set (JWKS) from https://github.com/login/oauth/.well-known/openid-configuration.
75+
1. Verify the token signature.
76+
1. Validate required claims.
77+
* `aud`: Audience. Your {% data variables.copilot.copilot_extension_short %}'s client ID.
78+
* `sub`: Subject. The {% data variables.product.github %} user ID making the request. The response is limited to data that the user has permissions to access. If the user has no permissions `400 Bad Request` is shown.
79+
* `iat`: Issued At. The timestamp when the token was issued. It is typically a timestamp in the past but represents the exact moment the token was created.
80+
* `nbf`: Not Before. The timestamp before which the token is not valid. This should be a timestamp in the past.
81+
* `exp`: Expiration Time. The timestamp when the token expires. This should be a timestamp in the future.
82+
* `act`: Actor. The acting entity in delegated access. This should be a constant string.
83+
84+
## Troubleshooting
85+
86+
The following sections outline common problems and best practices for implementing OIDC for your {% data variables.copilot.copilot_extension_short %}.
87+
88+
### Token validation errors
89+
90+
* Ensure you're using the correct JWKS endpoint.
91+
* Verify that all the required claims are present and valid.
92+
* Check that timestamps (`iat`, `nbf`, and `exp`) are within valid ranges.
93+
94+
### Token exchange failures
95+
96+
* Return `HTTP 400` for invalid tokens.
97+
* Return `HTTP 403` if the user lacks the necessary permissions.
98+
* If {% data variables.product.github %} receives a 403 response, it will retry the request with a new token.
99+
100+
### Performance issues
101+
102+
* Implement efficient token validation to minimize latency.
103+
* Use appropriate token expiration times (recommended: 10 minutes or less).
104+
* Consider caching implications for high-traffic extensions.
105+
106+
## Further reading
107+
108+
* [AUTOTITLE](/copilot/concepts/build-copilot-extensions/openid-connect)

content/copilot/how-tos/build-copilot-extensions/using-oidc-with-github-copilot-extensions.md

Lines changed: 0 additions & 175 deletions
This file was deleted.

0 commit comments

Comments
 (0)