Use single OIDC session auth method instead of per-provider values
The OIDC provider is already tracked in iam_oidc_states.provider, so there is no need for provider-specific session auth methods (GOOGLE, MICROSOFT). Replace them with a single OIDC auth method. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
ALTER TYPE session_auth_method ADD VALUE 'GOOGLE';
|
ALTER TYPE session_auth_method ADD VALUE 'OIDC';
|
||||||
ALTER TYPE session_auth_method ADD VALUE 'MICROSOFT';
|
|
||||||
|
|
||||||
CREATE TYPE iam_oidc_provider AS ENUM (
|
CREATE TYPE iam_oidc_provider AS ENUM (
|
||||||
'GOOGLE',
|
'GOOGLE',
|
||||||
|
|||||||
@@ -57,8 +57,7 @@ const (
|
|||||||
AuthMethodMagicLink AuthMethod = "MAGIC_LINK"
|
AuthMethodMagicLink AuthMethod = "MAGIC_LINK"
|
||||||
AuthMethodPassword AuthMethod = "PASSWORD"
|
AuthMethodPassword AuthMethod = "PASSWORD"
|
||||||
AuthMethodSAML AuthMethod = "SAML"
|
AuthMethodSAML AuthMethod = "SAML"
|
||||||
AuthMethodGoogle AuthMethod = "GOOGLE"
|
AuthMethodOIDC AuthMethod = "OIDC"
|
||||||
AuthMethodMicrosoft AuthMethod = "MICROSOFT"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewRootSession(identityID gid.GID, method AuthMethod, duration time.Duration) *Session {
|
func NewRootSession(identityID gid.GID, method AuthMethod, duration time.Duration) *Session {
|
||||||
|
|||||||
@@ -110,19 +110,11 @@ func (h *OIDCHandler) CallbackHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var authMethod coredata.AuthMethod
|
|
||||||
switch provider {
|
|
||||||
case coredata.OIDCProviderGoogle:
|
|
||||||
authMethod = coredata.AuthMethodGoogle
|
|
||||||
case coredata.OIDCProviderMicrosoft:
|
|
||||||
authMethod = coredata.AuthMethodMicrosoft
|
|
||||||
}
|
|
||||||
|
|
||||||
rootSession := authn.SessionFromContext(ctx)
|
rootSession := authn.SessionFromContext(ctx)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case rootSession == nil:
|
case rootSession == nil:
|
||||||
rootSession, err = h.iam.AuthService.OpenSessionWithOIDC(ctx, identity.ID, authMethod)
|
rootSession, err = h.iam.AuthService.OpenSessionWithOIDC(ctx, identity.ID, coredata.AuthMethodOIDC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logger.ErrorCtx(ctx, "cannot open root session", log.Error(err))
|
h.logger.ErrorCtx(ctx, "cannot open root session", log.Error(err))
|
||||||
httpserver.RenderError(w, http.StatusInternalServerError, errors.New("internal server error"))
|
httpserver.RenderError(w, http.StatusInternalServerError, errors.New("internal server error"))
|
||||||
@@ -136,7 +128,7 @@ func (h *OIDCHandler) CallbackHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rootSession, err = h.iam.AuthService.OpenSessionWithOIDC(ctx, identity.ID, authMethod)
|
rootSession, err = h.iam.AuthService.OpenSessionWithOIDC(ctx, identity.ID, coredata.AuthMethodOIDC)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.logger.ErrorCtx(ctx, "cannot open root session", log.Error(err))
|
h.logger.ErrorCtx(ctx, "cannot open root session", log.Error(err))
|
||||||
httpserver.RenderError(w, http.StatusInternalServerError, errors.New("internal server error"))
|
httpserver.RenderError(w, http.StatusInternalServerError, errors.New("internal server error"))
|
||||||
|
|||||||
Reference in New Issue
Block a user