...
1
21
22 package openid
23
24 import (
25 "context"
26
27 "github.com/ory/x/errorsx"
28
29 "github.com/ory/fosite"
30 )
31
32 type OpenIDConnectExplicitHandler struct {
33
34 OpenIDConnectRequestStorage OpenIDConnectRequestStorage
35 OpenIDConnectRequestValidator *OpenIDConnectRequestValidator
36
37 *IDTokenHandleHelper
38 }
39
40 var oidcParameters = []string{"grant_type",
41 "max_age",
42 "prompt",
43 "acr_values",
44 "id_token_hint",
45 "nonce",
46 }
47
48 func (c *OpenIDConnectExplicitHandler) HandleAuthorizeEndpointRequest(ctx context.Context, ar fosite.AuthorizeRequester, resp fosite.AuthorizeResponder) error {
49 if !(ar.GetGrantedScopes().Has("openid") && ar.GetResponseTypes().ExactOne("code")) {
50 return nil
51 }
52
53
54
55
56
57 if len(resp.GetCode()) == 0 {
58 return errorsx.WithStack(fosite.ErrMisconfiguration.WithDebug("The authorization code has not been issued yet, indicating a broken code configuration."))
59 }
60
61 if err := c.OpenIDConnectRequestValidator.ValidatePrompt(ctx, ar); err != nil {
62 return err
63 }
64
65 if err := c.OpenIDConnectRequestStorage.CreateOpenIDConnectSession(ctx, resp.GetCode(), ar.Sanitize(oidcParameters)); err != nil {
66 return errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithDebug(err.Error()))
67 }
68
69
70
71 return nil
72 }
73
View as plain text