mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
ddea31193b
OpenID connect has become a standard when it comes to authentication and in order to fix a security concern around forwarding authentication and authorization information it has been decided to add support for it. This feature is in beta version and only enabled when there is a configuration for it. Before enabling it in production, please consider that it's in beta with potential bugs and that there are several production critical features still missing such as all OIDC related data is stored in configuration or memory. This means you are potentially going to experience issues with HA deployments, or when restarting a single instance specifically related to OIDC. We are still working on adding the remaining set of features before making it GA as soon as possible. Related to #189 Co-authored-by: Clement Michaud <clement.michaud34@gmail.com>
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/ory/fosite"
|
|
|
|
"github.com/authelia/authelia/internal/middlewares"
|
|
)
|
|
|
|
func oidcToken(ctx *middlewares.AutheliaCtx, rw http.ResponseWriter, req *http.Request) {
|
|
oidcSession, err := newDefaultOIDCSession(ctx)
|
|
if err != nil {
|
|
ctx.Logger.Errorf("Error occurred in NewDefaultOIDCSession: %+v", err)
|
|
ctx.Providers.OpenIDConnect.Fosite.WriteAccessError(rw, nil, err)
|
|
|
|
return
|
|
}
|
|
|
|
accessRequest, accessReqErr := ctx.Providers.OpenIDConnect.Fosite.NewAccessRequest(ctx, req, oidcSession)
|
|
if accessReqErr != nil {
|
|
ctx.Logger.Errorf("Error occurred in NewAccessRequest: %+v", accessRequest)
|
|
ctx.Providers.OpenIDConnect.Fosite.WriteAccessError(rw, accessRequest, accessReqErr)
|
|
|
|
return
|
|
}
|
|
|
|
// If this is a client_credentials grant, grant all scopes the client is allowed to perform.
|
|
if accessRequest.GetGrantTypes().ExactOne("client_credentials") {
|
|
for _, scope := range accessRequest.GetRequestedScopes() {
|
|
if fosite.HierarchicScopeStrategy(accessRequest.GetClient().GetScopes(), scope) {
|
|
accessRequest.GrantScope(scope)
|
|
}
|
|
}
|
|
}
|
|
|
|
response, err := ctx.Providers.OpenIDConnect.Fosite.NewAccessResponse(ctx, accessRequest)
|
|
if err != nil {
|
|
ctx.Logger.Errorf("Error occurred in NewAccessResponse: %+v", err)
|
|
ctx.Providers.OpenIDConnect.Fosite.WriteAccessError(rw, accessRequest, err)
|
|
|
|
return
|
|
}
|
|
|
|
ctx.Providers.OpenIDConnect.Fosite.WriteAccessResponse(rw, accessRequest, response)
|
|
}
|