Skip to content

Commit f6b7228

Browse files
fix(providers): convert Salesforce to OIDC (#11918)
* fix(providers): convert Salesforce to OIDC fixes #11917 * add to examples * Update salesforce.ts
1 parent 6e24f7e commit f6b7228

File tree

3 files changed

+22
-38
lines changed

3 files changed

+22
-38
lines changed

apps/examples/nextjs/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Passkey from "next-auth/providers/passkey"
2424
import Pinterest from "next-auth/providers/pinterest"
2525
import Reddit from "next-auth/providers/reddit"
2626
import Slack from "next-auth/providers/slack"
27+
import Salesforce from "next-auth/providers/salesforce"
2728
import Spotify from "next-auth/providers/spotify"
2829
import Twitch from "next-auth/providers/twitch"
2930
import Twitter from "next-auth/providers/twitter"
@@ -88,6 +89,7 @@ const config = {
8889
Passage,
8990
Pinterest,
9091
Reddit,
92+
Salesforce,
9193
Slack,
9294
Spotify,
9395
Twitch,

apps/proxy/api/[auth].ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import Okta from "@auth/core/providers/okta"
2020
import Passage from "@auth/core/providers/passage"
2121
import Pinterest from "@auth/core/providers/pinterest"
2222
import Reddit from "@auth/core/providers/reddit"
23+
import Salesforce from "@auth/core/providers/salesforce"
2324
import Slack from "@auth/core/providers/slack"
2425
import Spotify from "@auth/core/providers/spotify"
2526
import Twitch from "@auth/core/providers/twitch"
@@ -59,6 +60,7 @@ const authConfig: AuthConfig = {
5960
Passage,
6061
Pinterest,
6162
Reddit,
63+
Salesforce,
6264
Slack,
6365
Spotify,
6466
Twitch,
Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* <div style={{backgroundColor: "#000", display: "flex", justifyContent: "space-between", color: "#fff", padding: 16}}>
2+
* <div style={{backgroundColor: "#00a1e0", display: "flex", justifyContent: "space-between", color: "#fff", padding: 16}}>
33
* <span>Built-in <b>Salesforce</b> integration.</span>
44
* <a href="https://www.salesforce.com/ap/?ir=1">
55
* <img style={{display: "block"}} src="https://authjs.dev/img/providers/salesforce.svg" height="48" />
@@ -8,7 +8,7 @@
88
*
99
* @module providers/salesforce
1010
*/
11-
import type { OAuthConfig, OAuthUserConfig } from "./index.js"
11+
import type { OIDCConfig, OIDCUserConfig } from "./index.js"
1212

1313
export interface SalesforceProfile extends Record<string, any> {
1414
sub: string
@@ -18,8 +18,6 @@ export interface SalesforceProfile extends Record<string, any> {
1818
}
1919

2020
/**
21-
* Add Salesforce login to your page.
22-
*
2321
* ### Setup
2422
*
2523
* #### Callback URL
@@ -28,66 +26,48 @@ export interface SalesforceProfile extends Record<string, any> {
2826
* ```
2927
*
3028
* #### Configuration
31-
*```ts
29+
* ```ts
3230
* import { Auth } from "@auth/core"
33-
* import salesforce from "@auth/core/providers/salesforce"
31+
* import Salesforce from "@auth/core/providers/salesforce"
3432
*
3533
* const request = new Request(origin)
3634
* const response = await Auth(request, {
3735
* providers: [
38-
* salesforce({
39-
* clientId: salesforce_CLIENT_ID,
40-
* clientSecret: salesforce_CLIENT_SECRET,
36+
* Salesforce({
37+
* clientId: AUTH_SALESFORCE_ID,
38+
* clientSecret: AUTH_SALESFORCE_SECRET,
4139
* }),
4240
* ],
4341
* })
4442
* ```
4543
*
4644
* ### Resources
4745
*
48-
* - [Salesforce OAuth documentation](https://help.salesforce.com/articleView?id=remoteaccess_authenticate.htm&type=5)
46+
* - [Auth0 docs](https://auth0.com/docs/authenticate)
4947
*
5048
* ### Notes
5149
*
52-
* By default, Auth.js assumes that the salesforce provider is
53-
* based on the [OAuth 2](https://www.rfc-editor.org/rfc/rfc6749.html) specification.
54-
*
55-
* :::tip
56-
*
57-
* The Salesforce provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/salesforce.ts).
58-
* To override the defaults for your use case, check out [customizing a built-in OAuth provider](https://authjs.dev/guides/configuring-oauth-providers).
50+
* The Salesforce provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/salesforce.ts). To override the defaults for your use case, check out [customizing a built-in OAuth provider](https://authjs.dev/guides/configuring-oauth-providers).
5951
*
60-
* :::
61-
*
62-
* :::info **Disclaimer**
52+
* ## Help
6353
*
6454
* If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue).
6555
*
6656
* Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from
6757
* the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec,
6858
* we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions).
69-
*
70-
* :::
7159
*/
72-
export default function Salesforce<P extends SalesforceProfile>(
73-
options: OAuthUserConfig<P>
74-
): OAuthConfig<P> {
75-
const { issuer = "https://login.salesforce.com" } = options
60+
export default function Salesforce(
61+
options: OIDCUserConfig<SalesforceProfile>
62+
): OIDCConfig<SalesforceProfile> {
7663
return {
7764
id: "salesforce",
7865
name: "Salesforce",
79-
type: "oauth",
80-
authorization: `${issuer}/services/oauth2/authorize?display=page`,
81-
token: `${issuer}/services/oauth2/token`,
82-
userinfo: `${issuer}/services/oauth2/userinfo`,
83-
profile(profile) {
84-
return {
85-
id: profile.user_id,
86-
name: null,
87-
email: null,
88-
image: profile.picture,
89-
}
90-
},
66+
type: "oidc",
67+
issuer: "https://login.salesforce.com",
68+
idToken: false,
69+
checks: ["pkce", "state", "nonce"],
70+
style: { bg: "#00a1e0" },
9171
options,
9272
}
9373
}

0 commit comments

Comments
 (0)