|
| 1 | +# vault-plugin-secrets-oauth-client-credentials |
| 2 | + |
| 3 | +This is a standalone secrets engine plugin for use with [Hashicorp |
| 4 | +Vault](https://www.github.com/hashicorp/vault). |
| 5 | + |
| 6 | +This plugin provides a secure wrapper around OAuth 2 authorization client credentials grant, also know as 2-legged OAuth which does not require authorization. |
| 7 | +Client credentials grant is used by clients to obtain an access token outside of the context of a user. This is typically used by clients to access resources about themselves rather than to access a user's resources. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +Download plugin's binary and [register the plugin with Vault](https://www.vaultproject.io/docs/internals/plugins.html#plugin-registration). We will assume it is registered under the name |
| 12 | +`oauthapp`. |
| 13 | + |
| 14 | +Mount the plugin at the path of your choosing: |
| 15 | + |
| 16 | +```console |
| 17 | +$ vault secrets enable -path=oauth2/my-provider oauthapp |
| 18 | +Success! Enabled the oauthapp secrets engine at: oauth2/my-provider/ |
| 19 | +``` |
| 20 | + |
| 21 | +Configure it with the necessary information to exchange tokens. Token URL shall point to an endpoint for obtaining tokens from your provider (it usually ends with `/token`). |
| 22 | + |
| 23 | +```console |
| 24 | +$ vault write oauth2/my-provider/config \ |
| 25 | + client_id=hOEvqqbHVlSNpuvY \ |
| 26 | + client_secret=6q2xrjZOJ1R9MfUvUxJzFAk \ |
| 27 | + token_url=https://example.com/token \ |
| 28 | + scopes=read.user,read.org |
| 29 | +Success! Data written to: oauth2/my-provider/config |
| 30 | +``` |
| 31 | + |
| 32 | +Once the client secret has been written, it will never be exposed again. |
| 33 | + |
| 34 | +To retrieve a token, read from the `/creds/:name` endpoint. The `name` identifier can be any arbitrary string. |
| 35 | + |
| 36 | +```console |
| 37 | +$ vault read oauth2/my-provider/creds/my-user |
| 38 | +Key Value |
| 39 | +--- ----- |
| 40 | +access_token RRcJk5r2BBUKsIquXaoVJfnSUX6uTkVReSaEthrgJmd8p9xlWPD0d0ADFgW5p6Glki5UNGEBGr6hWCEu |
| 41 | +expires 2020-10-25T13:43:56.6282713+01:00 |
| 42 | +``` |
| 43 | + |
| 44 | +You can override default scopes by specifying `scopes` parameter. This returns a new token with a new scope. |
| 45 | +```console |
| 46 | +$ vault read oauth2/my-provider/creds/my-user scopes=write.user,write.org |
| 47 | +Key Value |
| 48 | +--- ----- |
| 49 | +access_token vy7f9quvazKypM4FJ4WQMLCHkUEcDb2Z3ZifSWMi94Ur40Z3xf13dOj6Cydkp7vdoNRLQD2eOMFy0r2L |
| 50 | +expires 2020-10-25T13:44:07.1123581+01:00 |
| 51 | +``` |
| 52 | + |
| 53 | +The client secret is never exposed to Vault clients. |
| 54 | + |
| 55 | + |
| 56 | +## Endpoints |
| 57 | + |
| 58 | +### `config` |
| 59 | + |
| 60 | +#### `GET` (`read`) |
| 61 | + |
| 62 | +Retrieve the current configuration settings (except the client secret). |
| 63 | + |
| 64 | +#### `PUT` (`write`) |
| 65 | + |
| 66 | +Write new configuration settings. This endpoint completely replaces the existing |
| 67 | +configuration. |
| 68 | + |
| 69 | +| Name | Description | Type | Default | Required | |
| 70 | +|------|-------------|------|---------|----------| |
| 71 | +| `client_id` | The OAuth 2.0 client ID. | String | None | Yes | |
| 72 | +| `client_secret` | The OAuth 2.0 client secret. | String | None | Yes | |
| 73 | +| `token_url` | URL to obtain access tokens. | String | None | Yes | |
| 74 | +| `scopes` | Comma separated list of default explicit scopes. | List of String | None | No | |
| 75 | + |
| 76 | +#### `DELETE` (`delete`) |
| 77 | + |
| 78 | +Remove the current configuration. This does not invalidate any existing access |
| 79 | +tokens. |
| 80 | + |
| 81 | +### `creds/:name` |
| 82 | + |
| 83 | +#### `GET` (`read`) |
| 84 | + |
| 85 | +Retrieve a current access token for the given credential. |
| 86 | + |
| 87 | +| Name | Description | Type | Default | Required | |
| 88 | +|------|-------------|------|---------|----------| |
| 89 | +| `scopes` | A comma separated list of explicit scopes to override default scopes from config. If not specified, default `scopes` from config are used. | List of String | None | No | |
| 90 | + |
| 91 | +#### `DELETE` (`delete`) |
| 92 | + |
| 93 | +Remove the credential information from storage. This removes all scopes identified by the credential's `name`. |
0 commit comments