Skip to content

Commit 4953b37

Browse files
updating keyring_type docs (#38)
* update keyring type * update * updated with comments * nit * nit * updated * fix styling * format * Update keyrings.mdx --------- Co-authored-by: Karuna Tata <[email protected]>
1 parent 1be7aec commit 4953b37

File tree

1 file changed

+177
-135
lines changed

1 file changed

+177
-135
lines changed
Lines changed: 177 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Keyrings are a DevRev-specific mechanism for managing authentication with external services. Keyrings are called **Connections** in the DevRev app.
22

3-
Keyrings provide a secure way to store and manage credentials for external services within your DevRev snap-in. This eliminates the need to expose sensitive information like passwords or access tokens directly within your code or configuration files, enhancing overall security.
3+
Keyrings provides a secure way to store and manage credentials for external services within your DevRev snap-in. This eliminates the need to expose sensitive information like passwords or access tokens directly within your code or configuration files, enhancing overall security.
44

5-
Keyrings are defined in the snap-in manifest under the `keyrings` section. They can be categorized into two main types:
5+
For more information, refer to [Keyrings](/snapin-development/references/manifest#keyrings) in the snap-in manifest. They can be categorized into two main types:
66

77
1. **Default keyrings**:
8-
- **Organization scoped keyrings**: These are secrets used by the entire organization, for example a Slack token for a workspace.
9-
- **User scoped keyrings**: These are secrets for a single user, for example the token to interact with a single person's Google Calendar.
8+
- **Organization scoped keyrings**: These are secrets used by the entire organization, for example, a Slack token for a workspace.
9+
- **User scoped keyrings**: These are secrets for a single user, for example, the token to interact with a single person's Google Calendar.
1010

1111
<Callout intent="note">
1212
During installation, the user will be prompted to provide credentials for each keyring.
@@ -39,7 +39,7 @@ Breakdown:
3939
4040
- **display_name**: The name that's shown to the user when they're asked to provide a keyring.
4141
42-
All user scoped keyrings are optional in the snap-in, and developers must handle the case where a user scoped keyring isn't found.
42+
All user-scoped keyrings are optional in the snap-in, and developers must handle the case where a user-scoped keyring isn't found.
4343
4444
<Callout intent="note">
4545
If you are using version 1 of the manifest, you can omit the organization key in the keyring definition and directly provide the keyring definition as a list. All keyring defined in manifest version 1 are organization-scoped.
@@ -48,12 +48,12 @@ Additionally, the keyword `connections` is used instead of `keyrings` in manifes
4848

4949
2. **Developer scoped keyrings**: These are secrets accessible and usable only by the developer creating the snap-in, typically used for personal development workflows.
5050

51-
```yaml
52-
developer_keyrings:
53-
- name: my-secret-developer
54-
description: A secret for the developer to use during development
55-
display_name: Developer secret token
56-
```
51+
```yaml
52+
developer_keyrings:
53+
- name: my-secret-developer
54+
description: A secret for the developer to use during development
55+
display_name: Developer secret token
56+
```
5757
Breakdown:
5858

5959
- **name**: A unique identifier for the keyring in the snap-in.
@@ -62,38 +62,45 @@ Breakdown:
6262

6363
- **display_name**: The name that's shown to the user when they're asked to provide a keyring.
6464

65-
6665
## Enable external service connections with keyring types
6766

6867
While DevRev offers pre-defined keyring types for common services, you can leverage this mechanism further to create custom types for specific service integrations.
6968

70-
7169
### Pre-defined keyring types:
7270

7371
- **devrev-snap-in-secret**: Stores simple string tokens utilized by the snap-in itself.
7472

7573
- **devrev-atlassian-jira-oauth**: Facilitates OAuth connections for integrating with Jira.
74+
7675
```text
7776
scopes: offline_access read:me read:application-role:jira read:audit-log:jira read:issue-security-level:jira read:issue-security-scheme:jira read:project-role:jira read:avatar:jira read:project-category:jira read:project:jira read:permission-scheme:jira read:user:jira read:field:jira read:permission:jira read:group:jira read:project.component:jira read:issue-details:jira read:issue-meta:jira read:field-configuration:jira read:attachment:jira read:issue-link-type:jira read:issue-type-hierarchy:jira read:issue-type:jira read:label:jira read:priority:jira read:project.property:jira read:project-version:jira read:resolution:jira read:status:jira read:issue.changelog:jira read:issue:jira read:issue.vote:jira write:jira-work read:jira-work write:issue:jira write:issue.property:jira read:issue.transition:jira manage:jira-project manage:jira-configuration
7877
```
78+
7979
- **devrev-slack-oauth**: Facilitates OAuth connections for integrating with Slack.
80+
8081
```text
8182
scopes: app_mentions:read,channels:history,channels:read,channels:write.invites,channels:manage,chat:write,chat:write.customize,chat:write.public,commands,groups:history,groups:read,im:read,im:write,links:read,links:write,metadata.message:read,mpim:read,mpim:write,team:read,users.profile:read,users:read,users:read.email,im:history,mpim:history,files:read,files:write,pins:read,pins:write
8283
```
83-
- **devrev-google--oauth**: Facilitates OAuth connections for integrating with Google.
84+
85+
- **devrev-google-oauth**: Facilitates OAuth connections for integrating with Google.
86+
8487
```text
8588
scopes: https://www.googleapis.com/auth/gmail.send
8689
```
90+
8791
- **devrev-github-oauth**: Facilitates OAuth connections for integrating with GitHub.
92+
8893
```text
8994
scopes: repo admin:repo_hook admin:org notifications user write:discussion
9095
```
9196
- **devrev-zendesk-oauth**: Facilitates OAuth connections for integrating with Microsoft.
97+
9298
```text
9399
scopes: read tickets:write
94100
```
95101

96102
Manifest Declaration:
103+
97104
```yaml
98105
keyrings:
99106
organization:
@@ -109,135 +116,170 @@ While DevRev offers pre-defined keyring types for common services, you can lever
109116
- devrev-google-calendar-oauth
110117
display_name: Your secret token
111118
```
112-
113-
### Reuse pre-defined keyring types:
114-
While DevRev offers pre-defined keyring types for common services, these types provide further customization options for specific use cases. This section explores how you can leverage these predefined types and tailor them to your needs:
115-
116-
- **Client credentials**: These are credentials associated with your application, typically obtained from the service provider's developer console.
117-
- **Scopes**: These define the specific permissions your application requests from the service.
118-
119-
1. Creating a developer keyring
120-
121-
- 1.1 **CLI command**:
119+
3. **Custom keyring types for OAuth**:
120+
121+
Developer Keyring:
122+
- The `developer_keyrings` type allows the creation of keyrings that hold sensitive information like client IDs and client secrets required for OAuth authorization with external services. These keyrings are intended for development environments and should not be used in production due to security concerns.
123+
Here's an example configuration snippet demonstrating a `developer_keyring` named `custom-oauth-credentials`:
124+
125+
```yaml
126+
developer_keyrings:
127+
- name: custom-oauth-credentials
128+
description: A secret for the developer to use during development
129+
display_name: Developer secret token
130+
```
131+
132+
To create a developer keyring, follow these steps:
133+
- Replace `$CLIENT_CREDENTIALS` in the following command with your actual OAuth client ID and client secret combined into a JSON string.
134+
- Execute Command: Run the following command, replacing `<name of the keyring>` with your desired keyring name.
135+
122136
```bash
123-
echo $CLIENT_CREDENTIALS | devrev keyring create `oauth-secret`
124-
```
125-
Replace `$CLIENT_CREDENTIALS` with your actual OAuth client credentials.
126-
127-
- 1.2 **Manifest declaration**:
128-
```yaml
129-
developer_keyrings:
130-
- name: my-oauth-secret
131-
description: A secret for the developer to use during development
132-
display_name: Developer secret token
137+
echo $CLIENT_CREDENTIALS | devrev developer_keyring create oauth-secret <name of the keyring>
133138
```
134-
2. Customize predefined keyring type in manifest
135-
``` yaml
136-
keyring_types:
137-
- id: reference-oauth-example-connection
138-
name: Example OAuth Connection
139-
description: A custom keyring type for Example OAuth connections.
140-
kind: OAuth2
141-
scopes:
142-
- name: read
143-
description: Read access to Example resources
144-
value: read
145-
- name: write
146-
description: Write access to Example resources
147-
value: write
148-
is_optional: true
149-
oauth_secret: my-oauth-secret
150-
reference_keyring: devrev-example-oauth
151-
```
152-
**Breakdown** :
153-
- **id**: A unique identifier for your custom type.
154-
- **name**: A human-readable name for users.
155-
- **description**: A clear explanation of the type's purpose.
156-
- **kind**: Specifies the authentication method (here, OAuth2). Currently, only OAuth2 is supported.
157-
- **scopes**: Adjust scopes as needed based on your requirements.
158-
- **oauth_secret**: References the developer keyring where your credentials are stored.
159-
- **reference_keyring**: Utilizes pre-defined Example OAuth logic for handling the OAuth flow.
160-
161-
3. Keyring usage in manifest
139+
140+
<Callout intent="note">
141+
The keyring will be passed while `snap_in_version` is being created.
142+
</Callout>
143+
144+
Keyring usage in manifest:
145+
162146
```yaml
163-
keyrings:
164-
organization:
165-
- name: my-secret-org-token
166-
description: Enables access to organization-wide resources (e.g., Slack workspace)
167-
types:
168-
- reference-oauth-example-connection
169-
display_name: Organization secret token
147+
keyrings:
148+
organization:
149+
- name: example connection
150+
description: Enables access to organization-wide resources (e.g., Slack workspace)
151+
types:
152+
- custom-example-connection
153+
display_name: Organization secret token
154+
user:
155+
- name: example connection
156+
description: Enables access to organization-wide resources (e.g., Slack workspace)
157+
types:
158+
- custom-example-connection
159+
display_name: Organization secret token
170160
```
161+
162+
3.1. **Reusing Predefined keyring_type with Custom Scopes**:
163+
Here's an example of a custom keyring type for an existing OAuth2 keyring type while customizing the required scopes for your specific external service.
164+
165+
```yaml
166+
keyring_types:
167+
- id: custom-example-connection
168+
name: Example OAuth Connection
169+
description: A custom keyring type for Example OAuth connections.
170+
kind: OAuth2
171+
oauth_secret: custom-oauth-credentials # Developer keyring that contains OAuth2 client ID and client secret. Shall be of keyring type `oauth-secret`.
172+
reference_keyring: devrev-example-oauth # Predefined keyring type to be used as a reference for the custom keyring type
173+
scopes:
174+
- name: read
175+
description: Read access to Example resources
176+
value: read
177+
- name: write
178+
description: Write access to Example resources
179+
value: write
180+
is_optional: true
181+
```
182+
183+
3.2. **Custom keyring type definition**:
184+
This approach defines a new, entirely custom keyring type with complete control over the OAuth flow configuration.
185+
186+
```yaml
187+
keyring_types:
188+
- id: custom-example-connection // Unique identifier for your custom type, used in the `keyring` section of the manifest.
189+
name: "Example Connection"
190+
description: "Example connection"
191+
kind: "Oauth2"
192+
scopes: # Configuration for the scopes required by the external service for authorization
193+
- name: "read"
194+
description: "Read access to Example resources"
195+
value: "read"
196+
- name: "write"
197+
description: "Write access to Example resources"
198+
value: "write"
199+
is_optional: true
200+
scope_delimiter: "," # Delimiter used to separate scopes in the authorization request
201+
oauth_secret: custom-oauth-credentials # Developer keyring that contains OAuth2 client ID and client secret. Shall be of keyring type `oauth-secret`.
202+
authorize: # Configuration for the authorization request
203+
type: "config"
204+
grant_type: "authorization_code"
205+
auth_url: "https://example.com/oauth/authorize"
206+
token_url: "https://example.com/oauth/token"
207+
organization_data: # Configuration for fetching organization data
208+
type: "config"
209+
url: "https://example.com/oauth/organization"
210+
method: "POST"
211+
headers:
212+
"Content-type": "application/x-www-form-urlencoded"
213+
"Authorization": "Bearer [ACCESS_TOKEN]"
214+
response_jq: "{id:.team_id, name:.team}"
215+
refresh: # Configuration for the refresh token request
216+
type: "config"
217+
url: "https://example.com/oauth/token"
218+
method: "POST"
219+
revoke: # Configuration for the token revocation of the token
220+
type: "config"
221+
url: "https://example.com/oauth/revoke"
222+
method: "GET"
223+
headers:
224+
"Content-type": "application/x-www-form-urlencoded"
225+
"Authorization": "Bearer [ACCESS_TOKEN]"
226+
```
227+
228+
4. **Define Basic keyring type:**
229+
Here's an example of a custom keyring type for establishing secure Basic Auth connections within your snap-in:
171230
172-
### Custom keyring type definition:
231+
```yaml
232+
keyring_types:
233+
- id: custom-example-connection
234+
name: Basic Auth Connection
235+
description: A custom keyring type for Basic Auth connections.
236+
kind: secret
237+
secret_config: # Configuration for the secret fields required for Basic Auth
238+
- secret_transform: .token | base64 # Base64 encoding for the token
239+
fields:
240+
- id: token
241+
name: token
242+
description: Token for Basic Auth
243+
token_verfication: # Configuration for verifying the token given by the user
244+
- url: "https://example.com/verify"
245+
method: "POST"
246+
headers:
247+
"Content-type": "application/x-www-form-urlencoded"
248+
"Authorization": "Bearer [API_KEY]"
249+
```
173250
174-
This document details the complete configuration of a custom keyring type for establishing secure OAuth connections within your DevRev snap-in.
175-
In this example, we'll create a custom keyring type for an OAuth2 connection.
251+
5. **Define Multi-filed keyring:**
252+
Here's an example of a custom keyring type for establishing secure connections with multiple fields within your snap-in:
176253
177-
```yaml
254+
```yaml
178255
keyring_types:
179-
- id: "custom-oauth-example-connection" // Unique identifier for your custom type, used in the `keyring` section of the manifest.
180-
name: "Example Connection"
181-
description: "Example connection"
182-
kind: "Oauth2"
183-
scopes:
184-
- name: "read"
185-
description: "Read access to Example resources"
186-
value: "read"
187-
- name: "write"
188-
description: "Write access to Example resources"
189-
value: "write"
190-
is_optional: true
191-
oauth_secret: "example-oauth-secret" // Developer keyring reference
192-
authorize:
193-
type: "config"
194-
auth_url: "https://example.com/oauth/authorize"
195-
token_url: "https://example.com/oauth/token"
196-
grant_type: "authorization_code"
197-
organization_data:
198-
type: "config"
199-
url: "https://example.com/oauth/organization"
200-
method: "POST"
201-
headers:
202-
"Content-type": "application/x-www-form-urlencoded"
203-
"Authorization": "Bearer [ACCESS_TOKEN]"
204-
response_jq: "{id:.team_id, name:.team}"
205-
refresh:
206-
type: "config"
207-
url: "https://example.com/oauth/token"
208-
method: "POST"
209-
revoke:
210-
type: "config"
211-
url: "https://example.com/oauth/revoke"
212-
method: "GET"
213-
headers:
214-
"Content-type": "application/x-www-form-urlencoded"
215-
"Authorization": "Bearer [ACCESS_TOKEN]"
216-
```
256+
- id: custom-example-connection
257+
name: Multi-field Connection
258+
description: A custom keyring type for connections with multiple fields.
259+
kind: secret
260+
secret_config: # Configuration for the secret fields required for the connection
261+
fields:
262+
- id: token
263+
name: token
264+
description: Token for connection
265+
- id: username
266+
name: username
267+
description: Username for connection
268+
- id: password
269+
name: password
270+
description: Password for connection
271+
```
217272
273+
<Callout intent="note">
218274
219-
Breakdown:
275+
**Supported keywords in keyring_type configuration**:
276+
The supported keywords that can be dynamically inserted into URLs, headers, and query parameters within your custom keyring type configuration.
277+
- **[ACCESS_TOKEN]**: The access token obtained during the OAuth flow.
278+
- **[REFRESH_TOKEN]**: The refresh token obtained during the OAuth flow.
279+
- **[CLIENT_ID]**: The client ID obtained from the OAuth client credentials.
280+
- **[CLIENT_SECRET]**: The client secret obtained from the OAuth client credentials.
281+
- **[SCOPE]**: The scope of the OAuth flow.
282+
- **[API_KEY]**: The API key obtained from the basic flow.
283+
</Callout>
220284
221-
- **id**: A unique identifier for your custom type.
222-
- **name**: User-friendly name displayed in the manifest.
223-
- **description**: Clear explanation of the type's purpose.
224-
- **kind**: Specifies the authentication method (OAuth2).
225-
- **scopes**: Permissions requested from Example (adjust based on your needs).
226-
- **oauth_secret**: References the developer keyring containing your credentials.
227-
228-
Additional configuration:
229-
230-
- **authorize**: Defines the OAuth authorization flow.
231-
- **type**: Set to "config" as configuration details are provided. Currently, only "config" is supported.
232-
- **auth_url**: URL for user authorization.
233-
- **token_url**: URL to obtain access and refresh tokens.
234-
- **grant_type**: Grant type used in the authorization request. Currently, only "authorization_code" is supported.
235-
236-
- **organization_data**: Retrieves organization information after successful authorization.
237-
- **refresh**: Defines how to refresh access tokens when they expire.
238-
- **revoke**: Defines how to revoke access tokens when necessary.
239-
- **url**: Endpoint for fetching organization data.
240-
- **method**: HTTP method for the request.
241-
- **headers**: Required headers for the request.
242-
- **query_parameters**: Optional query parameters for the request.
243-
- **response_jq**: JQ expression to extract relevant data from the response.
285+
For examples of how to use keyrings in your snap-in, refer to the [Keyring API documentation](https://github.com/devrev/snap-in-examples/tree/main/13-keyring-type).

0 commit comments

Comments
 (0)