Skip to content

feat(auth-oidc,dashboard,auth,js-sdk,types,medusa): generic OIDC auth provider#16023

Open
NicolasGorga wants to merge 7 commits into
developfrom
fix/sso-auth-provider
Open

feat(auth-oidc,dashboard,auth,js-sdk,types,medusa): generic OIDC auth provider#16023
NicolasGorga wants to merge 7 commits into
developfrom
fix/sso-auth-provider

Conversation

@NicolasGorga

Copy link
Copy Markdown
Contributor

Summary

What — What changes are introduced in this PR?

Please provide answer here

Why — Why are these changes relevant or necessary?

Please provide answer here

How — How have these changes been implemented?

Please provide answer here

Testing — How have these changes been tested, or how can the reviewer test the feature?

Please provide answer here


Examples

Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice.
This helps with documentation and ensures maintainers can quickly understand and verify the change.

// Example usage

Checklist

Please ensure the following before requesting a review:

  • I have added a changeset for this PR
    • Every non-breaking change should be marked as a patch
    • To add a changeset, run yarn changeset and follow the prompts
  • The changes are covered by relevant tests
  • I have verified the code works as intended locally
  • I have linked the related issue(s) if applicable

Additional Context

Add any additional context, related issues, or references that might help the reviewer understand this PR.

@NicolasGorga
NicolasGorga requested a review from a team as a code owner July 13, 2026 13:55
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5f4d722

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 80 packages
Name Type
@medusajs/auth-oidc Patch
@medusajs/dashboard Patch
@medusajs/auth Patch
@medusajs/js-sdk Patch
@medusajs/types Patch
@medusajs/medusa Patch
@medusajs/draft-order Patch
@medusajs/loyalty-plugin Patch
@medusajs/admin-bundler Patch
integration-tests-http Patch
@medusajs/event-bus-redis Patch
@medusajs/framework Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/query Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/medusa-oas-cli Patch
@medusajs/test-utils Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/event-bus-local Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/core-flows Patch
@medusajs/oas-github-ci Patch
@medusajs/http-types-generator Patch
@medusajs/cli Patch
@medusajs/deps Patch
@medusajs/eslint-plugin Patch
@medusajs/telemetry Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@NicolasGorga NicolasGorga changed the title Generic OIDC auth provider feat(auth-oidc,dashboard,auth,js-sdk,types,medusa): generic OIDC auth provider Jul 17, 2026
this.config_.callback_url,
]

if (!allowedCallbackUrls.includes(callbackUrl)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this already checked by the IdP? I guess a double line of defense is fine, and we prevent the user from even being redirected to Google. But it also means two places to maintain the allowlist. I don'd really know what the best practice is, I think I've always relied on the IdP, but maybe that wasn't ideal.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe the best would be to not check if this.config_.allowed_callback_urls is not defined, so it's up to the user to decide if they want the double check.

const body: Record<string, string> = req.body ?? {}

if (query.error) {
this.logger_?.error(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we shouldn't log an error here. This is the IdP telling us something went wrong in the auth, e.g. the user canceled, or access_denied. Neither is our app's fault, so an error log is noisy. As a minimum, I'd downgrade the log level, but I think it would be better to return the actual error instead of GENERIC_AUTH_ERROR and have a higher layer log the error and return an opaque message to the user.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree to lowering the level, but I don't think we should completely remove it. Would be useful for debugging.

</div>
) : (
isEmailPassInstalled && (
<Form {...form}>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not part of this PR, but it would be nice to extract the emailpass form to a component. It's quite deep now, while the SsoLogin component, which is at the same conceptual level is already extracted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: a lot of the auth logic here, especially related to MFA, is similar to the cloud auth and I imagine any auth we add in the future. Would be good to make it reusable where possible.

Comment on lines +382 to +396
// Fallback: process-local cache when no cache module is available
const now = Date.now()
const cached = discoveryCache.get(this.options_.issuer)
if (cached && cached.expiresAt > now) {
return cached.metadata
}

const metadata = (await Issuer.discover(this.options_.issuer)).metadata

discoveryCache.set(this.options_.issuer, {
metadata,
expiresAt: now + this.discoveryCacheTtlMs_,
})

return metadata

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

q: is this necessary? feels like an over-defensive mechanism. I don't think this is a consistent pattern across our modules, but correct me if I'm wrong.

Comment on lines +410 to +424
const isLocalhost =
url.hostname === "localhost" ||
url.hostname === "127.0.0.1" ||
url.hostname === "::1" ||
url.hostname === "[::1]"

if (
url.protocol !== "https:" &&
!(url.protocol === "http:" && isLocalhost)
) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`OIDC '${label}' must use https (http is only allowed for localhost)`
)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: shouldn't we allow localhost only in development?

const body: Record<string, string> = req.body ?? {}

if (query.error) {
this.logger_?.error(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

agree to lowering the level, but I don't think we should completely remove it. Would be useful for debugging.

Comment on lines +203 to +229
private static assertSecureIssuer_(value: string): void {
let url: URL
try {
url = new URL(value)
} catch (e) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"OIDC 'issuer' must be a valid URL"
)
}

const isLocalhost =
url.hostname === "localhost" ||
url.hostname === "127.0.0.1" ||
url.hostname === "::1" ||
url.hostname === "[::1]"

if (
url.protocol !== "https:" &&
!(url.protocol === "http:" && isLocalhost)
) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"OIDC 'issuer' must use https (http is only allowed for localhost)"
)
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this logic is repeated here and in the engine, would be better to reuse it from the engine

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thought: we need to document a warning that enabling some providers like Google or GitHub for admin users would technically allow any user to register with this route as an admin user.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
medusa-docs-ui 5f4d722 Commit Preview URL

Branch Preview URL
Jul 20 2026, 02:02 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
medusa-docs-cloud 5f4d722 Commit Preview URL

Branch Preview URL
Jul 20 2026, 02:01 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
medusa-docs-user-guide 5f4d722 Commit Preview URL

Branch Preview URL
Jul 20 2026, 02:01 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
medusa-docs-resources 5f4d722 Commit Preview URL

Branch Preview URL
Jul 20 2026, 02:06 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
medusa-docs-book 5f4d722 Commit Preview URL

Branch Preview URL
Jul 20 2026, 02:01 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 20, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
medusa-docs-api-reference 5f4d722 Commit Preview URL

Branch Preview URL
Jul 20 2026, 02:00 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants