Show why personal OIDC logins are refused
Personal Google and Microsoft accounts were rejected with a raw JSON unauthorized response after the OIDC callback. Redirect to a dedicated auth page that explains the enterprise-account requirement, and check enterprise eligibility before xms_edov so Microsoft consumer accounts get the same clear error. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
committed by
Cursor Agent
parent
b8c3fb086e
commit
d1814d7051
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@probo.com>.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
import { usePageTitle } from "@probo/hooks";
|
||||
import { useTranslate } from "@probo/i18n";
|
||||
import { Button } from "@probo/ui";
|
||||
|
||||
export default function PersonalAccountNotAllowedPage() {
|
||||
const { __ } = useTranslate();
|
||||
|
||||
usePageTitle(__("Enterprise account required"));
|
||||
|
||||
return (
|
||||
<div className="space-y-6 w-full">
|
||||
<div className="space-y-2 text-center">
|
||||
<h1 className="text-2xl font-bold">{__("Enterprise account required")}</h1>
|
||||
<p className="text-txt-tertiary">
|
||||
{__(
|
||||
"Personal Google and Microsoft accounts cannot be used to sign in. Please use your work or school account instead.",
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<Button className="w-full h-10" to="/auth/login">
|
||||
{__("Sign in")}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -127,6 +127,12 @@ const routes = [
|
||||
path: "magic-link-already-used",
|
||||
Component: lazy(() => import("./pages/iam/auth/MagicLinkAlreadyUsedPage")),
|
||||
},
|
||||
{
|
||||
path: "personal-account-not-allowed",
|
||||
Component: lazy(
|
||||
() => import("./pages/iam/auth/PersonalAccountNotAllowedPage"),
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -165,6 +165,30 @@ func (c *idTokenClaims) isEmailDomainOwnerVerified() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// validateIDTokenClaims enforces provider-specific account requirements.
|
||||
// Enterprise eligibility is checked before email-verification claims so
|
||||
// personal Google/Microsoft accounts surface ErrPersonalAccountNotAllowed
|
||||
// rather than a generic email-verification failure (e.g. missing xms_edov).
|
||||
func validateIDTokenClaims(info *providerInfo, claims *idTokenClaims) error {
|
||||
if claims.Email == "" {
|
||||
return NewMissingEmailClaimError()
|
||||
}
|
||||
|
||||
if !info.enterpriseChecker(claims) {
|
||||
return NewPersonalAccountNotAllowedError()
|
||||
}
|
||||
|
||||
if !info.trustProviderEmail && !claims.isEmailVerified() {
|
||||
return NewEmailNotVerifiedError()
|
||||
}
|
||||
|
||||
if info.requireEmailDomainOwnerVerified && !claims.isEmailDomainOwnerVerified() {
|
||||
return NewEmailNotVerifiedError()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
googleEndpoint = oauth2.Endpoint{
|
||||
AuthURL: "https://accounts.google.com/o/oauth2/v2/auth",
|
||||
@@ -423,20 +447,8 @@ func (s *Service) HandleCallback(
|
||||
return nil, "", nil, fmt.Errorf("cannot verify id token: %w", err)
|
||||
}
|
||||
|
||||
if claims.Email == "" {
|
||||
return nil, "", nil, NewMissingEmailClaimError()
|
||||
}
|
||||
|
||||
if !info.trustProviderEmail && !claims.isEmailVerified() {
|
||||
return nil, "", nil, NewEmailNotVerifiedError()
|
||||
}
|
||||
|
||||
if info.requireEmailDomainOwnerVerified && !claims.isEmailDomainOwnerVerified() {
|
||||
return nil, "", nil, NewEmailNotVerifiedError()
|
||||
}
|
||||
|
||||
if !info.enterpriseChecker(claims) {
|
||||
return nil, "", nil, NewPersonalAccountNotAllowedError()
|
||||
if err := validateIDTokenClaims(info, claims); err != nil {
|
||||
return nil, "", nil, err
|
||||
}
|
||||
|
||||
email, err := mail.ParseAddr(claims.Email)
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
package oidc
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -89,3 +90,65 @@ func TestIsEmailDomainOwnerVerified(t *testing.T) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateIDTokenClaims_PersonalAccounts(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := newTestService(t)
|
||||
|
||||
t.Run("rejects Google personal account without hosted domain", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := validateIDTokenClaims(
|
||||
s.providers[coredata.OIDCProviderGoogle],
|
||||
&idTokenClaims{
|
||||
Email: "user@gmail.com",
|
||||
EmailVerified: true,
|
||||
},
|
||||
)
|
||||
_, ok := errors.AsType[*ErrPersonalAccountNotAllowed](err)
|
||||
assert.True(t, ok, "got %T: %v", err, err)
|
||||
})
|
||||
|
||||
t.Run("rejects Microsoft personal account before xms_edov check", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := validateIDTokenClaims(
|
||||
s.providers[coredata.OIDCProviderMicrosoft],
|
||||
&idTokenClaims{
|
||||
Issuer: "https://login.microsoftonline.com/" + microsoftConsumerTenantID + "/v2.0",
|
||||
Email: "user@outlook.com",
|
||||
},
|
||||
)
|
||||
_, ok := errors.AsType[*ErrPersonalAccountNotAllowed](err)
|
||||
assert.True(t, ok, "got %T: %v", err, err)
|
||||
})
|
||||
|
||||
t.Run("accepts Google Workspace account with hosted domain", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := validateIDTokenClaims(
|
||||
s.providers[coredata.OIDCProviderGoogle],
|
||||
&idTokenClaims{
|
||||
Email: "user@acme.com",
|
||||
EmailVerified: true,
|
||||
HostedDomain: "acme.com",
|
||||
},
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("rejects Microsoft enterprise account missing xms_edov", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
err := validateIDTokenClaims(
|
||||
s.providers[coredata.OIDCProviderMicrosoft],
|
||||
&idTokenClaims{
|
||||
Issuer: "https://login.microsoftonline.com/tenant-id/v2.0",
|
||||
Email: "user@acme.com",
|
||||
},
|
||||
)
|
||||
_, ok := errors.AsType[*ErrEmailNotVerified](err)
|
||||
assert.True(t, ok, "got %T: %v", err, err)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"go.probo.inc/probo/pkg/coredata"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/iam"
|
||||
"go.probo.inc/probo/pkg/iam/oidc"
|
||||
"go.probo.inc/probo/pkg/mail"
|
||||
"go.probo.inc/probo/pkg/saferedirect"
|
||||
"go.probo.inc/probo/pkg/securecookie"
|
||||
@@ -130,6 +131,13 @@ func (h *OIDCHandler) CallbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
identity, continueURL, organizationID, err := h.iam.OIDCService.HandleCallback(ctx, provider, stateParam, code)
|
||||
if err != nil {
|
||||
if _, ok := errors.AsType[*oidc.ErrPersonalAccountNotAllowed](err); ok {
|
||||
h.logger.WarnCtx(ctx, "OIDC login rejected: personal account not allowed")
|
||||
http.Redirect(w, r, "/auth/personal-account-not-allowed", http.StatusFound)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
h.logger.ErrorCtx(ctx, "cannot handle OIDC callback", log.Error(err))
|
||||
httpserver.RenderError(w, http.StatusUnauthorized, errors.New("authentication failed"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user