-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
createAwsCognitoOAuthConfig()
(#311)
* Add cognito provider. * Update README. * Rename provider. * tweak order * fix * fix --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2023-2024 the Deno authors. All rights reserved. MIT license. | ||
import type { OAuth2ClientConfig } from "../deps.ts"; | ||
import { getRequiredEnv } from "./get_required_env.ts"; | ||
|
||
/** | ||
* Returns the OAuth configuration for an Amazon Cognito user pool. | ||
* | ||
* Requires `--allow-env[=AWS_COGNITO_CLIENT_ID,AWS_COGNITO_CLIENT_SECRET,AWS_COGNITO_DOMAIN]` | ||
* permissions and environment variables: | ||
* 1. `AWS_COGNITO_CLIENT_ID` | ||
* 2. `AWS_COGNITO_CLIENT_SECRET` | ||
* 3. `AWS_COGNITO_DOMAIN` | ||
* | ||
* @example | ||
* ```ts | ||
* import { createAwsCognitoOAuthConfig } from "https://deno.land/x/deno_kv_oauth/mod.ts"; | ||
* | ||
* const oauthConfig = createAwsCognitoOAuthConfig({ | ||
* redirectUri: "http://localhost:8000/callback", | ||
* scope: "openid" | ||
* }); | ||
* ``` | ||
* | ||
* @see {@link https://docs.aws.amazon.com/cognito/latest/developerguide/federation-endpoints-oauth-grants.html} | ||
*/ | ||
|
||
export function createAwsCognitoOAuthConfig( | ||
config: { | ||
/** @see {@linkcode OAuth2ClientConfig.redirectUri} */ | ||
redirectUri: string; | ||
/** @see {@linkcode OAuth2ClientConfig.defaults.scope} */ | ||
scope?: string | string[]; | ||
}, | ||
): OAuth2ClientConfig { | ||
const domain = getRequiredEnv("AWS_COGNITO_DOMAIN"); | ||
const baseURL = `https://${domain}/oauth2`; | ||
return { | ||
clientId: getRequiredEnv("AWS_COGNITO_CLIENT_ID"), | ||
clientSecret: getRequiredEnv("AWS_COGNITO_CLIENT_SECRET"), | ||
authorizationEndpointUri: `${baseURL}/authorize`, | ||
tokenUri: `${baseURL}/token`, | ||
redirectUri: config.redirectUri, | ||
defaults: { scope: config?.scope }, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters