MCPcopy
hub / github.com/ory/hydra / acceptConsentHandler

Function acceptConsentHandler

oauth2/oauth2_auth_code_test.go:114–155  ·  view source on GitHub ↗
(t *testing.T, c *client.Client, adminClient *hydra.APIClient, reg *driver.RegistrySQL, subject string, checkRequestPayload func(*hydra.OAuth2ConsentRequest) *hydra.AcceptOAuth2ConsentRequest)

Source from the content-addressed store, hash-verified

112}
113
114func acceptConsentHandler(t *testing.T, c *client.Client, adminClient *hydra.APIClient, reg *driver.RegistrySQL, subject string, checkRequestPayload func(*hydra.OAuth2ConsentRequest) *hydra.AcceptOAuth2ConsentRequest) http.HandlerFunc {
115 return func(w http.ResponseWriter, r *http.Request) {
116 challenge := r.URL.Query().Get("consent_challenge")
117 rr, _, err := adminClient.OAuth2API.GetOAuth2ConsentRequest(context.Background()).ConsentChallenge(challenge).Execute()
118 require.NoError(t, err)
119 require.Equal(t, challenge, rr.Challenge)
120
121 assert.EqualValues(t, c.GetID(), pointerx.Deref(rr.Client.ClientId))
122 assert.Empty(t, pointerx.Deref(rr.Client.ClientSecret))
123 assert.EqualValues(t, c.GrantTypes, rr.Client.GrantTypes)
124 assert.EqualValues(t, c.LogoURI, pointerx.Deref(rr.Client.LogoUri))
125 assert.EqualValues(t, c.RedirectURIs, rr.Client.RedirectUris)
126 assert.EqualValues(t, subject, pointerx.Deref(rr.Subject))
127 assert.EqualValues(t, []string{"hydra", "offline", "openid"}, rr.RequestedScope)
128 assert.Contains(t, *rr.RequestUrl, reg.Config().OAuth2AuthURL(r.Context()).String())
129 assert.Equal(t, map[string]interface{}{"context": "bar"}, rr.Context)
130
131 acceptBody := hydra.AcceptOAuth2ConsentRequest{
132 GrantScope: []string{"hydra", "offline", "openid"},
133 GrantAccessTokenAudience: rr.RequestedAccessTokenAudience,
134 Remember: new(true),
135 RememberFor: new(int64(0)),
136 Session: &hydra.AcceptOAuth2ConsentRequestSession{
137 AccessToken: map[string]interface{}{"foo": "bar"},
138 IdToken: map[string]interface{}{"bar": "baz", "email": "foo@bar.com"},
139 },
140 }
141 if checkRequestPayload != nil {
142 if b := checkRequestPayload(rr); b != nil {
143 acceptBody = *b
144 }
145 }
146
147 v, _, err := adminClient.OAuth2API.AcceptOAuth2ConsentRequest(context.Background()).
148 ConsentChallenge(challenge).
149 AcceptOAuth2ConsentRequest(acceptBody).
150 Execute()
151 require.NoError(t, err)
152 require.NotEmpty(t, v.RedirectTo)
153 http.Redirect(w, r, v.RedirectTo, http.StatusFound)
154 }
155}
156
157// TestAuthCodeWithDefaultStrategy runs proper integration tests against in-memory and database connectors, specifically
158// we test:

Calls 9

OAuth2AuthURLMethod · 0.80
GetMethod · 0.65
GetIDMethod · 0.65
StringMethod · 0.65
ConfigMethod · 0.65
ExecuteMethod · 0.45
ConsentChallengeMethod · 0.45

Tested by

no test coverage detected