mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
c9d86a9240
* feat(oidc): oauth2 discovery and endpoint rename This implements the oauth2 authorization server discovery document, adds tests to the discovery documents, implements an efficiency upgrade to these docs, and renames some endpoints to be uniform.
54 lines
1.5 KiB
Go
54 lines
1.5 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
"github.com/authelia/authelia/v4/internal/middlewares"
|
|
)
|
|
|
|
func wellKnownOpenIDConnectConfigurationGET(ctx *middlewares.AutheliaCtx) {
|
|
issuer, err := ctx.ExternalRootURL()
|
|
if err != nil {
|
|
ctx.Logger.Errorf("Error occurred determining OpenID Connect issuer details: %+v", err)
|
|
ctx.Response.SetStatusCode(fasthttp.StatusBadRequest)
|
|
|
|
return
|
|
}
|
|
|
|
wellKnown := ctx.Providers.OpenIDConnect.GetOpenIDConnectWellKnownConfiguration(issuer)
|
|
|
|
ctx.SetContentType("application/json")
|
|
|
|
if err = json.NewEncoder(ctx).Encode(wellKnown); err != nil {
|
|
ctx.Logger.Errorf("Error occurred in JSON encode: %+v", err)
|
|
// TODO: Determine if this is the appropriate error code here.
|
|
ctx.Response.SetStatusCode(fasthttp.StatusInternalServerError)
|
|
|
|
return
|
|
}
|
|
}
|
|
|
|
func wellKnownOAuthAuthorizationServerGET(ctx *middlewares.AutheliaCtx) {
|
|
issuer, err := ctx.ExternalRootURL()
|
|
if err != nil {
|
|
ctx.Logger.Errorf("Error occurred determining OpenID Connect issuer details: %+v", err)
|
|
ctx.Response.SetStatusCode(fasthttp.StatusBadRequest)
|
|
|
|
return
|
|
}
|
|
|
|
wellKnown := ctx.Providers.OpenIDConnect.GetOAuth2WellKnownConfiguration(issuer)
|
|
|
|
ctx.SetContentType("application/json")
|
|
|
|
if err = json.NewEncoder(ctx).Encode(wellKnown); err != nil {
|
|
ctx.Logger.Errorf("Error occurred in JSON encode: %+v", err)
|
|
// TODO: Determine if this is the appropriate error code here.
|
|
ctx.Response.SetStatusCode(fasthttp.StatusInternalServerError)
|
|
|
|
return
|
|
}
|
|
}
|