--- layout: docs page_title: JWT/OIDC - Auth Methods description: >- The JWT/OIDC auth method allows authentication using OIDC and user-provided JWTs --- # JWT/OIDC Auth Method @include 'x509-sha1-deprecation.mdx' The `jwt` auth method can be used to authenticate with Vault using [OIDC](https://en.wikipedia.org/wiki/OpenID_Connect) or by providing a [JWT](https://en.wikipedia.org/wiki/JSON_Web_Token). The OIDC method allows authentication via a configured OIDC provider using the user's web browser. This method may be initiated from the Vault UI or the command line. Alternatively, a JWT can be provided directly. The JWT is cryptographically verified using locally-provided keys, or, if configured, an OIDC Discovery service can be used to fetch the appropriate keys. The choice of method is configured per role. Both methods allow additional processing of the claims data in the JWT. Some of the concepts common to both methods will be covered first, followed by specific examples of OIDC and JWT usage. ## OIDC Authentication This section covers the setup and use of OIDC roles. If a JWT is to be provided directly, refer to the [JWT Authentication](/docs/auth/jwt#jwt-authentication) section below. Basic familiarity with [OIDC concepts](https://developer.okta.com/blog/2017/07/25/oidc-primer-part-1) is assumed. The Authorization Code flow makes use of the Proof Key for Code Exchange (PKCE) extension. Vault includes two built-in OIDC login flows: the Vault UI, and the CLI using a `vault login`. ### Redirect URIs An important part of OIDC role configuration is properly setting redirect URIs. This must be done both in Vault and with the OIDC provider, and these configurations must align. The redirect URIs are specified for a role with the `allowed_redirect_uris` parameter. There are different redirect URIs to configure the Vault UI and CLI flows, so one or both will need to be set up depending on the installation. **CLI** If you plan to support authentication via `vault login -method=oidc`, a localhost redirect URI must be set. This can usually be: `http://localhost:8250/oidc/callback`. Logins via the CLI may specify a different host and/or listening port if needed, and a URI with this host/port must match one of the configured redirected URIs. These same "localhost" URIs must be added to the provider as well. **Vault UI** Logging in via the Vault UI requires a redirect URI of the form: `https://{host:port}/ui/vault/auth/{path}/oidc/callback` The "host:port" must be correct for the Vault server, and "path" must match the path the JWT backend is mounted at (e.g. "oidc" or "jwt"). If the [oidc_response_mode](/api-docs/auth/jwt#oidc_response_mode) is set to `form_post`, then logging in via the Vault UI requires a redirect URI of the form: `https://{host:port}/v1/auth/{path}/oidc/callback` Prior to Vault 1.6, if [namespaces](/docs/enterprise/namespaces) are in use, they must be added as query parameters, for example: `https://vault.example.com:8200/ui/vault/auth/oidc/oidc/callback?namespace=my_ns` For Vault 1.6+, it is no longer necessary to add the namespace as a query parameter in the redirect URI, if [`namespace_in_state`](/api-docs/auth/jwt#namespace_in_state) is set to `true`, which is the default for new configs. ### OIDC Login (Vault UI) 1. Select the "OIDC" login method. 1. Enter a role name if necessary. 1. Press "Sign In" and complete the authentication with the configured provider. ### OIDC Login (CLI) The CLI login defaults to path of `/oidc`. If this auth method was enabled at a different path, specify `-path=/my-path` in the CLI. ```shell-session $ vault login -method=oidc port=8400 role=test Complete the login via your OIDC provider. Launching browser to: https://myco.auth0.com/authorize?redirect_uri=http%3A%2F%2Flocalhost%3A8400%2Foidc%2Fcallback&client_id=r3qXc2bix9eF... ``` The browser will open to the generated URL to complete the provider's login. The URL may be entered manually if the browser cannot be automatically opened. - `skip_browser` (default: "false"). Toggle the automatic launching of the default browser to the login URL. The callback listener may be customized with the following optional parameters. These are typically not required to be set: - `mount` (default: "oidc") - `listenaddress` (default: "localhost") - `port` (default: 8250) - `callbackhost` (default: "localhost") - `callbackmethod` (default: "http") - `callbackport` (default: value set for `port`). This value is used in the `redirect_uri`, whereas `port` is the localhost port that the listener is using. These two may be different in advanced setups. ### OIDC Provider Configuration The OIDC authentication flow has been successfully tested with a number of providers. A full guide to configuring OAuth/OIDC applications is beyond the scope of Vault documentation, but a collection of provider configuration steps has been collected to help get started: [OIDC Provider Setup](/docs/auth/jwt_oidc_providers) ### OIDC Configuration Troubleshooting This amount of configuration required for OIDC is relatively small, but it can be tricky to debug why things aren't working. Some tips for setting up OIDC: - If a role parameter (e.g. `bound_claims`) requires a map value, it can't be set individually using the Vault CLI. In these cases the best approach is to write the entire configuration as a single JSON object: ```text vault write auth/oidc/role/demo -<":""`. Assume `claim_mappings` is set to: ```json { "division": "organization", "department": "department" } ``` This specifies that the value in the JWT claim "division" should be copied to the metadata key "organization". The JWT "department" claim value will also be copied into metadata but will retain the key name. If a claim is configured in `claim_mappings`, it must existing in the JWT or else the authentication will fail. Note: the metadata key name "role" is reserved and may not be used for claim mappings. ### Claim Specifications and JSON Pointer Some parameters (e.g. `bound_claims`, `groups_claim`, `claim_mappings`, `user_claim`) are used to point to data within the JWT. If the desired key is at the top of level of the JWT, the name can be provided directly. If it is nested at a lower level, a JSON Pointer may be used. Assume the following JSON data to be referenced: ```json { "division": "North America", "groups": { "primary": "Engineering", "secondary": "Software" } } ``` A parameter of `"division"` will reference "North America", as this is a top level key. A parameter `"/groups/primary"` uses JSON Pointer syntax to reference "Engineering" at a lower level. Any valid JSON Pointer can be used as a selector. Refer to the [JSON Pointer RFC](https://tools.ietf.org/html/rfc6901) for a full description of the syntax. ## API The JWT Auth Plugin has a full HTTP API. Please see the [API docs](/api-docs/auth/jwt) for more details.