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

Add workos authkit provider #12505

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

fierysolid
Copy link

@fierysolid fierysolid commented Jan 15, 2025

☕️ Reasoning

WorkOS has added their own IDP in the form of AuthKit and I'd like to use it with next-auth

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

📌 Resources

Copy link

vercel bot commented Jan 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ❌ Failed (Inspect) Jan 16, 2025 9:20pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Jan 16, 2025 9:20pm

Copy link

vercel bot commented Jan 15, 2025

@fierysolid is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

@fierysolid
Copy link
Author

I would love feedback about how I've implemented the provider from someone who has worked with this library extensively. Using request and conform feels like I'm doing something wrong, but this a working configuration.

},
userinfo: {
url: "https://api.workos.com/user_management/users",
async request({ tokens, provider }) {
Copy link
Author

@fierysolid fierysolid Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The /user_management/authenticate (token) call actually returns the user profile at the same time, so you could in theory just immediately return tokens.user, but I assumed there may be other places where the "userinfo" endpoint gets called to get an updated profile.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great reasoning. I think it’s best to wait for an official response from a maintainer regarding how the userinfo property/request works.

Copy link
Contributor

@halvaradop halvaradop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve read the documentation, but I’m confused about the focus of this provider. According to their explanation:

If you are using AuthKit, set the provider parameter to authkit, which will generate an authorization URL for your AuthKit domain. AuthKit will take care...
Otherwise, to generate an authorization URL for a WorkOS SSO connection, you’ll need to specify the user’s connection, organization, or OAuth provider as a parameter.

Based on this, if the user selects an authkitProvider value other than authkit, do they need to set both the connection_id and organization_id? If so, these values don’t seem to be available in the provider options for configuration.

On the other hand, Auth.js already includes a provider called WorkOs. What is the difference between this and the one mentioned in the documentation? Do you know if this API is still functional?

Thanks for your time!

Comment on lines 9 to 19
export interface AuthKitProfile extends Record<string, any> {
object: string
id: string
email: string
email_verified: boolean
first_name: string
last_name: string
profile_picture_url: string | null
created_at: string
updated_at: string
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the WorkOS documentation, the properties first_name, last_name, and profile_picture_url are optional. Therefore, sometimes these attributes may not exist, which can cause errors in the profile function since these properties, please read

profile(profile) {
return {
id: profile.id,
name: `${profile.first_name} ${profile.last_name}`,
email: profile.email,
image: profile.profile_picture_url ?? null,
}
},

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll update the types and profile.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and made those properties string | null | undefined because the docs say string | undefined, but the API returns string | null. This covers all bases. Additionally, in the profile function I use a waterfall approach to generate name from first_name and last_name.

@fierysolid
Copy link
Author

fierysolid commented Jan 15, 2025

I’ve read the documentation, but I’m confused about the focus of this provider. According to their explanation:

If you are using AuthKit, set the provider parameter to authkit, which will generate an authorization URL for your AuthKit domain. AuthKit will take care...
Otherwise, to generate an authorization URL for a WorkOS SSO connection, you’ll need to specify the user’s connection, organization, or OAuth provider as a parameter.

Based on this, if the user selects an authkitProvider value other than authkit, do they need to set both the connection_id and organization_id? If so, these values don’t seem to be available in the provider options for configuration.

On the other hand, Auth.js already includes a provider called WorkOs. What is the difference between this and the one mentioned in the documentation? Do you know if this API is still functional?

Thanks for your time!

WorkOS has an SSO passthrough and they also now have an IDP. The WorkOS provider is for the SSO only API, and this provider is for the IDP + SSO API which uses different URLs. The new IDP + SSO API also lets you use AuthKit while the older SSO API does not.

@halvaradop
Copy link
Contributor

Thank you for taking the time to provide a response. The differences and improvements applied to the new provider compared to the older one make perfect sense. 🤠

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Refers to `@auth/core` examples providers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants