Skip to content

Commit

Permalink
fix(providers): refactor WorkOS to work in v4 (#3886)
Browse files Browse the repository at this point in the history
* refactor(dev): moved dev app

* chore(dev): fix dev app

* fix(providers): WorkOS to TS, use `client_secret_post`

* chore: decrease test concurrency

* chore: remove org

* chore: run tests sequentially

* feat(providers): use `picture` in WorkOS if available
  • Loading branch information
balazsorban44 committed Feb 13, 2022
1 parent 2e37105 commit caa9a17
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
5 changes: 5 additions & 0 deletions apps/dev/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import OsuProvider from "next-auth/providers/osu"
import AppleProvider from "next-auth/providers/apple"
import PatreonProvider from "next-auth/providers/patreon"
import TraktProvider from "next-auth/providers/trakt"
import WorkOSProvider from "next-auth/providers/workos"

// import { PrismaAdapter } from "@next-auth/prisma-adapter"
// import { PrismaClient } from "@prisma/client"
Expand Down Expand Up @@ -195,6 +196,10 @@ export const authOptions: NextAuthOptions = {
clientId: process.env.TRAKT_ID,
clientSecret: process.env.TRAKT_SECRET,
}),
WorkOSProvider({
clientId: process.env.WORKOS_ID,
clientSecret: process.env.WORKOS_SECRET,
}),
],
debug: true,
theme: {
Expand Down
22 changes: 0 additions & 22 deletions packages/next-auth/src/providers/workos.js

This file was deleted.

48 changes: 48 additions & 0 deletions packages/next-auth/src/providers/workos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface WorkOSProfile {
object: string
id: string
organization_id: string
connection_id: string
connection_type: string
idp_id: string
email: string
first_name: string
last_name: string
raw_attributes: {
id: string
email: string
lastName: string
firstName: string
}
}

export default function WorkOS<P extends Record<string, any> = WorkOSProfile>(
options: OAuthUserConfig<P>
): OAuthConfig<P> {
const { issuer = "https://api.workos.com/" } = options

return {
id: "workos",
name: "WorkOS",
type: "oauth",
authorization: `${issuer}sso/authorize`,
token: {
url: `${issuer}sso/token`,
},
client: {
token_endpoint_auth_method: "client_secret_post",
},
userinfo: `${issuer}sso/profile`,
profile(profile) {
return {
id: profile.id,
name: `${profile.first_name} ${profile.last_name}`,
email: profile.email,
image: profile.raw_attributes.picture ?? null,
}
},
options,
}
}

0 comments on commit caa9a17

Please sign in to comment.