|
| 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) |
0 commit comments