Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: createLinkedInOAuthConfig() #287

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ The following providers have pre-defined OAuth configurations:
1. [GitHub](https://deno.land/x/deno_kv_oauth/mod.ts?s=createGitHubOAuthConfig)
1. [GitLab](https://deno.land/x/deno_kv_oauth/mod.ts?s=createGitLabOAuthConfig)
1. [Google](https://deno.land/x/deno_kv_oauth/mod.ts?s=createGoogleOAuthConfig)
1. [LinkedIn](https://deno.land/x/deno_kv_oauth/mod.ts?s=createLinkedInOAuthConfig)
1. [Notion](https://deno.land/x/deno_kv_oauth/mod.ts?s=createNotionOAuthConfig)
1. [Okta](https://deno.land/x/deno_kv_oauth/mod.ts?s=createOktaOAuthConfig)
1. [Patreon](https://deno.land/x/deno_kv_oauth/mod.ts?s=createPatreonOAuthConfig)
Expand Down
39 changes: 39 additions & 0 deletions lib/create_linkedin_oauth_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023 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 LinkedIn.
*
* Requires `--allow-env[=LINKEDIN_CLIENT_ID,LINKEDIN_CLIENT_SECRET]` permissions
* and environment variables:
* 1. `LINKEDIN_CLIENT_ID`
* 2. `LINKEDIN_CLIENT_SECRET`
*
* @example
* ```ts
* import { createLinkedInOAuthConfig } from "https://deno.land/x/deno_kv_oauth@$VERSION/mod.ts";
*
* const oauthConfig = createLinkedInOAuthConfig({
* redirectUri: "http://localhost:8000/callback",
* scope: "r_liteprofile r_emailaddress"
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
* });
* ```
*
* @see {@link https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin%2Fcontext&tabs=HTTPS1}
*/
export function createLinkedInOAuthConfig(config: {
/** @see {@linkcode OAuth2ClientConfig.redirectUri} */
redirectUri: string;
/** @see {@linkcode OAuth2ClientConfig.defaults}*/
scope: string | string[];
}): OAuth2ClientConfig {
return {
clientId: getRequiredEnv("LINKEDIN_CLIENT_ID"),
clientSecret: getRequiredEnv("LINKEDIN_CLIENT_SECRET"),
authorizationEndpointUri: "https://www.linkedin.com/oauth/v2/authorization",
tokenUri: "https://www.linkedin.com/oauth/v2/accessToken",
redirectUri: config.redirectUri,
defaults: { scope: config.scope },
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
};
}
5 changes: 5 additions & 0 deletions lib/create_oauth_config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { createFacebookOAuthConfig } from "./create_facebook_oauth_config.ts";
import { createGitHubOAuthConfig } from "./create_github_oauth_config.ts";
import { createGitLabOAuthConfig } from "./create_gitlab_oauth_config.ts";
import { createGoogleOAuthConfig } from "./create_google_oauth_config.ts";
import { createLinkedInOAuthConfig } from "./create_linkedin_oauth_config.ts";
import { createNotionOAuthConfig } from "./create_notion_oauth_config.ts";
import { createOktaOAuthConfig } from "./create_okta_oauth_config.ts";
import { createPatreonOAuthConfig } from "./create_patreon_oauth_config.ts";
Expand Down Expand Up @@ -43,6 +44,10 @@ import { createTwitterOAuthConfig } from "./create_twitter_oauth_config.ts";
envPrefix: "GOOGLE",
createOAuthConfigFn: createGoogleOAuthConfig,
},
{
envPrefix: "LINKEDIN",
createOAuthConfigFn: createLinkedInOAuthConfig,
},
{
envPrefix: "NOTION",
createOAuthConfigFn: createNotionOAuthConfig,
Expand Down
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./lib/create_facebook_oauth_config.ts";
export * from "./lib/create_github_oauth_config.ts";
export * from "./lib/create_gitlab_oauth_config.ts";
export * from "./lib/create_google_oauth_config.ts";
export * from "./lib/create_linkedin_oauth_config.ts";
export * from "./lib/create_notion_oauth_config.ts";
export * from "./lib/create_okta_oauth_config.ts";
export * from "./lib/create_patreon_oauth_config.ts";
Expand Down
Loading