Skip to content

Commit f635035

Browse files
fix(provider): refactor Okta provider (#2856)
* fix(provider): refactor Okta provider * fix(providers): convert Okta to TS * fix: typo * fix(okta): adds picture to profile Co-authored-by: Balázs Orbán <info@balazsorban.com> * fix(provider): refactor Okta provider fix(providers): convert Okta to TS fix: typo * fix: resolves merge conflicts Co-authored-by: Balázs Orbán <info@balazsorban.com>
1 parent 50e6a64 commit f635035

File tree

3 files changed

+62
-20
lines changed

3 files changed

+62
-20
lines changed

app/pages/api/auth/[...nextauth].ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import AzureADProvider from "next-auth/providers/azure-ad"
2121
import SpotifyProvider from "next-auth/providers/spotify"
2222
import CognitoProvider from "next-auth/providers/cognito"
2323
import SlackProvider from "next-auth/providers/slack"
24+
import Okta from "next-auth/providers/okta"
2425

2526
// import { PrismaAdapter } from "@next-auth/prisma-adapter"
2627
// import { PrismaClient } from "@prisma/client"
@@ -150,6 +151,11 @@ export default NextAuth({
150151
clientSecret: process.env.COGNITO_SECRET,
151152
issuer: process.env.COGNITO_ISSUER,
152153
}),
154+
Okta({
155+
clientId: process.env.OKTA_ID,
156+
clientSecret: process.env.OKTA_SECRET,
157+
issuer: process.env.OKTA_ISSUER,
158+
}),
153159
SlackProvider({
154160
clientId: process.env.SLACK_ID,
155161
clientSecret: process.env.SLACK_SECRET,

src/providers/okta.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/providers/okta.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { OAuthConfig, OAuthUserConfig } from "."
2+
3+
export interface OktaProfile {
4+
iss: string
5+
ver: string
6+
sub: string
7+
aud: string
8+
iat: string
9+
exp: string
10+
jti: string
11+
auth_time: string
12+
amr: string
13+
idp: string
14+
nonce: string
15+
name: string
16+
nickname: string
17+
preferred_username: string
18+
given_name: string
19+
middle_name: string
20+
family_name: string
21+
email: string
22+
email_verified: string
23+
profile: string
24+
zoneinfo: string
25+
locale: string
26+
address: string
27+
phone_number: string
28+
picture: string
29+
website: string
30+
gender: string
31+
birthdate: string
32+
updated_at: string
33+
at_hash: string
34+
c_hash: string
35+
}
36+
37+
export default function Okta<P extends Record<string, any> = OktaProfile>(
38+
options: OAuthUserConfig<P>
39+
): OAuthConfig<P> {
40+
return {
41+
id: "okta",
42+
name: "Okta",
43+
type: "oauth",
44+
wellKnown: `${options.issuer}/.well-known/openid-configuration`,
45+
authorization: { params: { scope: "openid email profile" } },
46+
profile(profile) {
47+
return {
48+
id: profile.sub,
49+
name: profile.name ?? profile.preferred_username,
50+
email: profile.email,
51+
image: profile.picture,
52+
}
53+
},
54+
options,
55+
}
56+
}

0 commit comments

Comments
 (0)