Skip to content

Commit

Permalink
Merge pull request #500 from curveball/refactor-discovery
Browse files Browse the repository at this point in the history
Move oauth2 discovery docs logic
  • Loading branch information
evert authored Jul 19, 2024
2 parents 9a226ef + b9bac9a commit b4b4dbd
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 30 deletions.
28 changes: 0 additions & 28 deletions src/oauth2/formats/json.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
import { OAuth2Token } from '../types.js';
import { resolve } from 'url';
import { getGlobalOrigin } from '@curveball/kernel';

export function metadata() {

return {
issuer: getGlobalOrigin(),
authorization_endpoint: '/authorize',

token_endpoint: '/token',
token_endpoint_auth_methods_supported: ['client_secret_basic'],
token_endpoint_auth_signing_alg_values_supported: ['RS256'],

jwks_uri: resolve(getGlobalOrigin(), '/.well-known/jwks.json'),

scopes_supported: ['openid'],

response_types_supported: ['token', 'code', 'code id_token'],
grant_types_supported: ['client_credentials', 'implicit', 'authorization_code', 'refresh_token'],
id_token_signing_alg_values_supported: ['RS256'],

service_documentation: getGlobalOrigin(),
ui_locales_supported: ['en'],
introspection_endpoint: '/introspect',
revocation_endpoint: '/revoke',
revocation_endpoint_auth_methods_supported: ['client_secret_basic'],
};

}
export function tokenResponse(token: OAuth2Token) {
return {
access_token: token.accessToken,
Expand Down
2 changes: 1 addition & 1 deletion src/well-known/controller/oauth2-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Controller from '@curveball/controller';
import { Context } from '@curveball/core';
import { metadata } from '../../oauth2/formats/json.js';
import { metadata } from '../formats/json.js';

class MetadataController extends Controller {

Expand Down
2 changes: 1 addition & 1 deletion src/well-known/controller/openid-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Controller from '@curveball/controller';
import { Context } from '@curveball/core';
import { metadata } from '../../oauth2/formats/json.js';
import { metadata } from '../formats/json.js';

class MetadataController extends Controller {

Expand Down
67 changes: 67 additions & 0 deletions src/well-known/formats/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { resolve } from 'url';
import { getGlobalOrigin } from '@curveball/kernel';

type AuthMethod = 'client_secret_basic';
type SigningAlgs = 'RS256';

type GrantType = 'client_credentials' | 'implicit' | 'authorization_code' | 'refresh_token';

type ResponseType = 'token' | 'code' | 'code id_token';

type MetaData = {
issuer: string;
authorization_endpoint: string;
token_endpoint: string;

token_endpoint_auth_methods_supported: AuthMethod[];
token_endpoint_auth_signing_alg_values_supported: SigningAlgs[];

jwks_uri: string;
scopes_supported: string[];

response_types_supported: ResponseType[];
grant_types_supported: GrantType[];

id_token_signing_alg_values_supported: SigningAlgs[];

service_documentation: string;
ui_locales_supported: string[];

introspection_endpoint: string;
revocation_endpoint: string;
revocation_endpoint_auth_methods_supported: AuthMethod[];

// https://www.ietf.org/archive/id/draft-parecki-oauth-first-party-apps-00.html
authorization_challenge_endpoint: string;

}

export function metadata(): MetaData {

return {
issuer: getGlobalOrigin(),
authorization_endpoint: '/authorize',

token_endpoint: '/token',
token_endpoint_auth_methods_supported: ['client_secret_basic'],
token_endpoint_auth_signing_alg_values_supported: ['RS256'],

jwks_uri: resolve(getGlobalOrigin(), '/.well-known/jwks.json'),

scopes_supported: ['openid'],

response_types_supported: ['token', 'code', 'code id_token'],
grant_types_supported: ['client_credentials', 'implicit', 'authorization_code', 'refresh_token'],
id_token_signing_alg_values_supported: ['RS256'],

service_documentation: getGlobalOrigin(),
ui_locales_supported: ['en'],
introspection_endpoint: '/introspect',
revocation_endpoint: '/revoke',
revocation_endpoint_auth_methods_supported: ['client_secret_basic'],

authorization_challenge_endpoint: '/authorization-challenge',

};

}

0 comments on commit b4b4dbd

Please sign in to comment.