Skip to content

Commit

Permalink
feat(js): fetchOidcConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
IceHe committed Jan 28, 2022
1 parent 0e22f23 commit b4f05d0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"dependencies": {
"@silverhand/essentials": "^1.1.5",
"camelcase-keys": "^7.0.1",
"jose": "^4.3.8",
"js-base64": "^3.7.2",
"lodash.get": "^4.4.2",
Expand Down
26 changes: 26 additions & 0 deletions packages/js/src/core/oidc-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { fetchOidcConfig } from './oidc-config';

describe('fetchOidcConfig', () => {
test('should return OidcConfigResponse with camel case keys', async () => {
const requester = jest.fn().mockResolvedValue({
authorization_endpoint: 'foo',
token_endpoint: 'foo',
userinfo_endpoint: 'foo',
end_session_endpoint: 'foo',
revocation_endpoint: 'foo',
jwks_uri: 'foo',
issuer: 'foo',
});
await expect(
fetchOidcConfig('https://example.com/oidc/.well-known/openid-configuration', requester)
).resolves.toEqual({
authorizationEndpoint: 'foo',
tokenEndpoint: 'foo',
userinfoEndpoint: 'foo',
endSessionEndpoint: 'foo',
revocationEndpoint: 'foo',
jwksUri: 'foo',
issuer: 'foo',
});
});
});
22 changes: 22 additions & 0 deletions packages/js/src/core/oidc-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { KeysToCamelCase } from '@silverhand/essentials';
import camelcaseKeys from 'camelcase-keys';

import { createRequester, Requester } from '../utils/requester';

type OidcConfigSnakeCaseResponse = {
authorization_endpoint: string;
token_endpoint: string;
userinfo_endpoint: string;
end_session_endpoint: string;
revocation_endpoint: string;
jwks_uri: string;
issuer: string;
};

export type OidcConfigResponse = KeysToCamelCase<OidcConfigSnakeCaseResponse>;

export const fetchOidcConfig = async (
endpoint: string,
requester: Requester = createRequester()
): Promise<OidcConfigResponse> =>
camelcaseKeys(await requester<OidcConfigSnakeCaseResponse>(endpoint));
26 changes: 23 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b4f05d0

Please sign in to comment.