2021-05-04 22:06:05 +00:00
|
|
|
package oidc
|
|
|
|
|
|
|
|
import (
|
2022-03-04 03:09:27 +00:00
|
|
|
"fmt"
|
2021-07-10 04:56:33 +00:00
|
|
|
|
2022-11-13 03:26:10 +00:00
|
|
|
"github.com/ory/fosite"
|
2022-10-20 02:16:36 +00:00
|
|
|
"github.com/ory/fosite/handler/openid"
|
2021-07-10 04:56:33 +00:00
|
|
|
"github.com/ory/herodot"
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
2022-04-07 05:33:53 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/storage"
|
2023-01-07 20:04:06 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/templates"
|
2021-05-04 22:06:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewOpenIDConnectProvider new-ups a OpenIDConnectProvider.
|
2023-05-22 11:14:32 +00:00
|
|
|
func NewOpenIDConnectProvider(config *schema.OpenIDConnect, store storage.Provider, templates *templates.Provider) (provider *OpenIDConnectProvider) {
|
2022-04-07 05:33:53 +00:00
|
|
|
if config == nil {
|
2023-05-15 00:03:19 +00:00
|
|
|
return nil
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
2022-10-20 02:16:36 +00:00
|
|
|
provider = &OpenIDConnectProvider{
|
|
|
|
JSONWriter: herodot.NewJSONWriter(nil),
|
2022-11-13 03:26:10 +00:00
|
|
|
Store: NewStore(config, store),
|
2023-05-15 00:03:19 +00:00
|
|
|
KeyManager: NewKeyManager(config),
|
2023-01-07 20:04:06 +00:00
|
|
|
Config: NewConfig(config, templates),
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2022-11-13 03:26:10 +00:00
|
|
|
provider.OAuth2Provider = fosite.NewOAuth2Provider(provider.Store, provider.Config)
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2022-11-13 03:26:10 +00:00
|
|
|
provider.Config.Strategy.OpenID = &openid.DefaultStrategy{
|
2023-05-15 00:03:19 +00:00
|
|
|
Signer: provider.KeyManager,
|
2022-11-13 03:26:10 +00:00
|
|
|
Config: provider.Config,
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
|
|
|
|
2023-05-15 00:03:19 +00:00
|
|
|
provider.Config.LoadHandlers(provider.Store, provider.KeyManager)
|
2023-05-14 23:51:59 +00:00
|
|
|
provider.Config.Strategy.ClientAuthentication = provider.DefaultClientAuthenticationStrategy
|
2021-05-04 22:06:05 +00:00
|
|
|
|
2023-04-13 10:58:18 +00:00
|
|
|
provider.discovery = NewOpenIDConnectWellKnownConfiguration(config)
|
2021-07-10 04:56:33 +00:00
|
|
|
|
2023-05-15 00:03:19 +00:00
|
|
|
return provider
|
2021-05-04 22:06:05 +00:00
|
|
|
}
|
2021-07-10 04:56:33 +00:00
|
|
|
|
2022-03-04 03:09:27 +00:00
|
|
|
// GetOAuth2WellKnownConfiguration returns the discovery document for the OAuth Configuration.
|
2022-10-20 02:16:36 +00:00
|
|
|
func (p *OpenIDConnectProvider) GetOAuth2WellKnownConfiguration(issuer string) OAuth2WellKnownConfiguration {
|
2023-04-13 10:58:18 +00:00
|
|
|
options := p.discovery.OAuth2WellKnownConfiguration.Copy()
|
2022-03-04 03:09:27 +00:00
|
|
|
|
|
|
|
options.Issuer = issuer
|
|
|
|
|
2023-03-06 03:58:50 +00:00
|
|
|
options.JWKSURI = fmt.Sprintf("%s%s", issuer, EndpointPathJWKs)
|
2022-10-20 02:16:36 +00:00
|
|
|
options.AuthorizationEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathAuthorization)
|
2023-03-06 03:58:50 +00:00
|
|
|
options.PushedAuthorizationRequestEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathPushedAuthorizationRequest)
|
|
|
|
options.TokenEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathToken)
|
|
|
|
options.IntrospectionEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathIntrospection)
|
2022-10-20 02:16:36 +00:00
|
|
|
options.RevocationEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathRevocation)
|
2022-03-04 03:09:27 +00:00
|
|
|
|
|
|
|
return options
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetOpenIDConnectWellKnownConfiguration returns the discovery document for the OpenID Configuration.
|
2022-10-20 02:16:36 +00:00
|
|
|
func (p *OpenIDConnectProvider) GetOpenIDConnectWellKnownConfiguration(issuer string) OpenIDConnectWellKnownConfiguration {
|
2023-04-13 10:58:18 +00:00
|
|
|
options := p.discovery.Copy()
|
2022-03-04 03:09:27 +00:00
|
|
|
|
|
|
|
options.Issuer = issuer
|
|
|
|
|
2023-03-06 03:58:50 +00:00
|
|
|
options.JWKSURI = fmt.Sprintf("%s%s", issuer, EndpointPathJWKs)
|
2022-10-20 02:16:36 +00:00
|
|
|
options.AuthorizationEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathAuthorization)
|
2023-03-06 03:58:50 +00:00
|
|
|
options.PushedAuthorizationRequestEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathPushedAuthorizationRequest)
|
|
|
|
options.TokenEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathToken)
|
2022-10-20 02:16:36 +00:00
|
|
|
options.UserinfoEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathUserinfo)
|
2023-03-06 03:58:50 +00:00
|
|
|
options.IntrospectionEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathIntrospection)
|
|
|
|
options.RevocationEndpoint = fmt.Sprintf("%s%s", issuer, EndpointPathRevocation)
|
2022-03-04 03:09:27 +00:00
|
|
|
|
|
|
|
return options
|
|
|
|
}
|