This module contains simple OIDC provider metadata retrieval functions usable by Deno. The intent is to retrieve all standard OIDC 1.0 metadata so that another OAuth 2 library can be initialized with the right endpoints. This module has no external runtime dependencies.
Retrieve the raw OIDC 1.0 provider metadata for a given issuer URL. Calls the standard metadata endpoint for the issuer and returns the object retrieved with no further validation or transformation.
issuer: string | URL
options?: Readonly<OidcDiscoveryOptions>
Promise<RawProviderMetadata>
Retrieve the OIDC 1.0 provider metadata for a given issuer URL and parse it into ProviderMetadata
. Calls the standard metadata endpoint for the issuer then does basic parsing and validation to ensure that the metadata is valid.
issuer: string | URL
options?: Readonly<OidcDiscoveryOptions>
Promise<ProviderMetadata>
An example program that uses the oauth2_client
module to perform a client credentials grant and retrieve the access token for a specific client ID then prints the token and information to the console:
import { retrieveProviderMetadata } from "https://deno.land/x/oidc_discovery/mod.ts";
import { OAuth2Client } from "https://deno.land/x/[email protected]/mod.ts";
const issuer = Deno.env.get("ISSUER");
const clientId = Deno.env.get("CLIENT_ID");
const clientSecret = Deno.env.get("CLIENT_SECRET");
const metadata = await retrieveProviderMetadata(issuer!);
const client = new OAuth2Client({
clientId: clientId!,
clientSecret: clientSecret,
authorizationEndpointUri: metadata.authorizationEndpoint.href,
tokenUri: metadata.tokenEndpoint.href,
});
const tokens = await client.clientCredentials.getToken();
console.log(tokens);
import { retrieveRawProviderMetadata } from "https://deno.land/x/oidc_discovery/mod.ts";
if(Deno.args.length == 0) {
console.error("issuer URL(s) required!")
console.error();
console.error("USAGE:");
console.error("\tdeno run --allow-net get_issuer_metadata.ts <issuer URL>...");
}
for(const issuer of Deno.args) {
const metadata = await retrieveRawProviderMetadata(issuer);
console.log(JSON.stringify(metadata, null, 2));
console.log();
}
A number of tasks are set up in the Deno project to make development easier:
test
-- Runs the tests (in the/tests
directory).fmt
-- Runsdeno fmt
on all the source code.check
-- Runsdeno check
on all the source code.lint
-- Runsdeno lint
on all the source code.