API: Implement OIDC login endpoint #782

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2024-06-27 10:42:42 +02:00
parent 7dff5511bc
commit 412a6e9b7a
2 changed files with 56 additions and 7 deletions

View File

@@ -31,16 +31,51 @@ func OIDCRedirect(router *gin.RouterGroup) {
actor := "unknown client"
action := "redirect"
// Abort if running in public mode.
// Get global config.
conf := get.Config()
// Abort in public mode and if OIDC is disabled.
if get.Config().Public() {
event.AuditErr([]string{clientIp, "oidc", actor, action, authn.ErrDisabledInPublicMode.Error()})
Abort(c, http.StatusForbidden, i18n.ErrForbidden)
return
} else if !conf.OIDCEnabled() {
event.AuditErr([]string{clientIp, "oidc", actor, action, authn.ErrAuthenticationDisabled.Error()})
Abort(c, http.StatusMethodNotAllowed, i18n.ErrUnsupported)
return
}
// TODO
// Get OIDC provider.
provider := get.OIDC()
if provider == nil {
event.AuditErr([]string{clientIp, "oidc", actor, action, authn.ErrAuthenticationDisabled.Error()})
Abort(c, http.StatusInternalServerError, i18n.ErrConnectionFailed)
return
}
_, claimErr := provider.CodeExchangeUserInfo(c)
if claimErr != nil {
event.AuditErr([]string{clientIp, "oidc", actor, action, claimErr.Error()})
Abort(c, http.StatusForbidden, i18n.ErrForbidden)
return
}
// TODO 1: Create user account if it does not exist yet.
/*
user := &entity.User{
DisplayName: userInfo.GetName(),
UserName: oidc.UsernameFromUserInfo(userInfo),
UserEmail: userInfo.GetEmail(),
AuthID: userInfo.GetSubject(),
AuthProvider: authn.ProviderOIDC.String(),
} */
// TODO 2: Create and return user session.
// TODO 3: Render HTML template to set the access token in localStorage.
// Send response.
c.JSON(http.StatusMethodNotAllowed, gin.H{"status": StatusFailed})
})
}