Skip to content

Commit

Permalink
(improvement, yaml): Update default OAuth configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney committed May 8, 2024
1 parent 9851238 commit b9029f0
Show file tree
Hide file tree
Showing 31 changed files with 658 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,18 @@ interface OAuthRefreshTokenRequestPropertyComponents {
}

export function getTokenEndpoint(oauthSchema: RawSchemas.OAuthSchemeSchema): TokenEndpoint {
// const maybeScopes = oauthSchema["get-token"]["request-properties"].scopes;
const maybeScopes = oauthSchema["get-token"]["request-properties"].scopes;
const maybeExpiresIn = oauthSchema["get-token"]["response-properties"]["expires-in"];
const maybeRefreshToken = oauthSchema["get-token"]["response-properties"]["refresh-token"];
return {
endpoint: oauthSchema["get-token"].endpoint,
// TODO: Update the YAML schema and make this configurable with the following:
// requestProperties: {
// type: "access_token",
// client_id: getRequestPropertyComponents(oauthSchema["get-token"]["request-properties"]["client-id"]),
// client_secret: getRequestPropertyComponents(
// oauthSchema["get-token"]["request-properties"]["client-secret"]
// ),
// scopes: maybeScopes != null ? getRequestPropertyComponents(maybeScopes) : undefined
// },
requestProperties: {
type: "access_token",
client_id: ["client_id"],
client_secret: ["client_secret"],
scopes: undefined
client_id: getRequestPropertyComponents(oauthSchema["get-token"]["request-properties"]["client-id"]),
client_secret: getRequestPropertyComponents(
oauthSchema["get-token"]["request-properties"]["client-secret"]
),
scopes: maybeScopes != null ? getRequestPropertyComponents(maybeScopes) : undefined
},
responseProperties: {
type: "access_token",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: invalid
imports:
name: missing
imports:
auth: auth.yml

auth: OAuthScheme
auth-schemes:
OAuthScheme:
scheme: oauth
type: client-credentials
get-token:
get-token:
endpoint: auth.getTokenWithClientCredentials
response-properties:
access-token: $response.missing.access_token
expires-in: $response.missing.expires_in
refresh-token:
response-properties:
access-token: $response.accessToken
expires-in: $response.expiresIn
refresh-token:
endpoint: auth.refreshToken
request-properties:
refresh-token: $request.refreshTokenDoesNotExist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ service:
getTokenWithClientCredentials:
path: /token
method: POST
request:
request:
name: GetTokenRequest
body:
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: invalid
imports:
auth: auth.yml

auth: OAuthScheme
auth-schemes:
OAuthScheme:
scheme: oauth
type: client-credentials
get-token:
endpoint: auth.getToken
request-properties:
client-id: $request.credentials.client_id
client-secret: $request.credentials.client_secret
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
types:
TokenCredentials:
docs: |
The credentials required to retrieve an access token.
properties:
client_id: string
client_secret: string

TokenResponse:
docs: |
An OAuth token response.
properties:
access_token: string
expires_in: integer
refresh_token: optional<string>

service:
auth: false
base-path: /
endpoints:
getToken:
path: /token
method: POST
request:
name: GetTokenRequest
body:
properties:
credentials: TokenCredentials
response: TokenResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: invalid
imports:
auth: auth.yml

auth: OAuthScheme
auth-schemes:
OAuthScheme:
scheme: oauth
type: client-credentials
get-token:
endpoint: auth.getToken
request-properties:
scopes: $request.scopes
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
types:
TokenResponse:
docs: |
An OAuth token response.
properties:
access_token: string
expires_in: integer
refresh_token: optional<string>

service:
auth: false
base-path: /
endpoints:
getToken:
path: /token
method: POST
request:
name: GetTokenRequest
body:
properties:
client_id: uuid
client_secret: uuid
scopes: integer
response: TokenResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: alias
imports:
auth: auth.yml

auth: OAuthScheme
auth-schemes:
OAuthScheme:
scheme: oauth
type: client-credentials
get-token:
endpoint: auth.getToken
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
types:
ClientID: string
ClientSecret: string
AccessToken: string

TokenResponse:
docs: |
An OAuth token response.
properties:
access_token: AccessToken

service:
auth: false
base-path: /
endpoints:
getToken:
path: /token
method: POST
request:
name: GetTokenRequest
body:
properties:
client_id: ClientID
client_secret: ClientSecret
grant_type: literal<"client_credentials">
response: TokenResponse
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: valid-default
imports:
auth: auth.yml

auth: OAuthScheme
auth-schemes:
OAuthScheme:
scheme: oauth
type: client-credentials
get-token:
endpoint: auth.getToken
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
types:
TokenResponse:
docs: |
An OAuth token response.
properties:
access_token: string

service:
auth: false
base-path: /
endpoints:
getToken:
path: /token
method: POST
request:
name: GetTokenRequest
body:
properties:
client_id: string
client_secret: string
grant_type: literal<"client_credentials">
response: TokenResponse

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: valid-default
imports:
auth: auth.yml

auth: OAuthScheme
auth-schemes:
OAuthScheme:
scheme: oauth
type: client-credentials
get-token:
endpoint: auth.getToken
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
types:
TokenResponse:
docs: |
An OAuth token response.
properties:
access_token: string

service:
auth: false
base-path: /
endpoints:
getToken:
path: /token
method: GET
request:
name: GetTokenRequest
query-parameters:
client_id: string
client_secret: string
response: TokenResponse
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: valid
imports:
imports:
auth: auth.yml

auth: OAuthScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ service:
getTokenWithClientCredentials:
path: /token
method: POST
request:
request:
name: GetTokenRequest
body:
properties:
Expand All @@ -28,7 +28,7 @@ service:
refreshToken:
path: /token
method: POST
request:
request:
name: RefreshTokenRequest
body:
properties:
Expand Down

0 comments on commit b9029f0

Please sign in to comment.