Skip to content

Commit

Permalink
Merge pull request #141 from krakend/token_tests
Browse files Browse the repository at this point in the history
expired tokens refreshed
  • Loading branch information
kpacha authored Jan 15, 2025
2 parents bff5338 + 0c34aa6 commit 95ec430
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions gin/jose_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Example_RS256() {
// output:
// token request
// 201
// {"access_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTEtMDQtMjkiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.SFy8lloEcTMGb7twtxOPMZE1zPccGDVylsrjyvMj_DTZbKacq5WZsyvtG_InjKvRTn_xSC3JQkeCRFTCXFyQEJMyjhWgCAZ4QHXXDHyXSHnvIh1_hDQW5BrIDslWsftg3KYPFAXB2i78p1kioqQSa9NmikgRChjx-InqUM599yRaOB4Z_Xjg7DCIkgIO01JfsXU6IxEskGVuXcIV1EY44CT84I5w-Mr0fwGOyqKMmUodji2raI_SIYRb2EBTtoDBlabB19Dulv8puq4LacjQaRIuWQbA40hGOiepchJMApBaiX6QdYXTnc0f6RFE5GiX1-oYWgOQNi3OA2gJ61PLLA","exp":1735689600,"refresh_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTEtMDQtMjkiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXB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lenNPdfGPL6E3uL1nqPHcxhte7ikSG4Q6Q","exp":2051882755,"refresh_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTEtMDQtMjkiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoyMDUxODgyNzU1LCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uMTI4NzZidmN4OThlcnR5dWlvcCIsInN1YiI6IjEyMzQ1Njc4OTBxd2VydHl1aW8ifQ.jwmNRj7gRcAgeeG9WqB2I8mqRVFZtw3uw5uSBJD8MmCVGRGPJ83ytEbqF3A-ya9IbdL5lJZ5LDUhwkO9xnkLZPBClDYBP81h0ZU7KR3vJnH9ZNkgpUiu1XLfkpJ6tSuZXPLj5-Lxymr3Mf8PdWey5YjEfk6mN_xfBHZR_XZbwsVbiv_nWhp-qeltPkXraShEpsDFFfzjRFrGprFi1S00OFDBcObbmXtZ8GTyJgSN8vO_rU-vkt6no1phKHzuyaS5D6GdjrxDXv7pHYL-OWifBiElMs09PAd16rZy3-qSIDZS7vHo724cG9UYMgxSE86PvjGP_dOJCOf64p_wPkkBRw"}
// map[Content-Type:[application/json; charset=utf-8]]
// unauthorized request
// 401
Expand All @@ -49,7 +49,7 @@ func Example_RS256() {
// application/json; charset=utf-8
// refresh token request
// 201
// {"access_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTEtMDQtMjkiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ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8GTyJgSN8vO_rU-vkt6no1phKHzuyaS5D6GdjrxDXv7pHYL-OWifBiElMs09PAd16rZy3-qSIDZS7vHo724cG9UYMgxSE86PvjGP_dOJCOf64p_wPkkBRw"}
// application/json; charset=utf-8
// DEBUG: [ENDPOINT: /private][JWTSigner] Signer disabled
// DEBUG: [ENDPOINT: /private][JWTValidator] Roles will be matched against the key: 'roles'
Expand Down Expand Up @@ -78,7 +78,7 @@ func Example_HS256() {
// output:
// token request
// 201
// {"access_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.89zdRo4LCHpT93JX3_Yn2LoAOUvEAiFj6X7vnCgOd5Q","exp":1735689600,"refresh_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uMTI4NzZidmN4OThlcnR5dWlvcCIsInN1YiI6IjEyMzQ1Njc4OTBxd2VydHl1aW8ifQ.lJuO1xyI8QOTWNGxBQe2hH90Jdp5y0DEbPd44I728dA"}
// {"access_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoyMDUxODgyNzU1LCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.xG6O62h475Y-EknyLFerPOUX6ATKCoIYEq4QsQsuw-Q","exp":2051882755,"refresh_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoyMDUxODgyNzU1LCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uMTI4NzZidmN4OThlcnR5dWlvcCIsInN1YiI6IjEyMzQ1Njc4OTBxd2VydHl1aW8ifQ.8rd0w9_H7Z_0J37nKvqQNwJnP25VrQcVAAa5sc3Fsw0"}
// map[Content-Type:[application/json; charset=utf-8]]
// unauthorized request
// 401
Expand All @@ -92,7 +92,7 @@ func Example_HS256() {
// application/json; charset=utf-8
// refresh token request
// 201
// {"access_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.89zdRo4LCHpT93JX3_Yn2LoAOUvEAiFj6X7vnCgOd5Q","exp":1735689600,"refresh_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uMTI4NzZidmN4OThlcnR5dWlvcCIsInN1YiI6IjEyMzQ1Njc4OTBxd2VydHl1aW8ifQ.lJuO1xyI8QOTWNGxBQe2hH90Jdp5y0DEbPd44I728dA"}
// {"access_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoyMDUxODgyNzU1LCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.xG6O62h475Y-EknyLFerPOUX6ATKCoIYEq4QsQsuw-Q","exp":2051882755,"refresh_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoyMDUxODgyNzU1LCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uMTI4NzZidmN4OThlcnR5dWlvcCIsInN1YiI6IjEyMzQ1Njc4OTBxd2VydHl1aW8ifQ.8rd0w9_H7Z_0J37nKvqQNwJnP25VrQcVAAa5sc3Fsw0"}
// application/json; charset=utf-8
// DEBUG: [ENDPOINT: /private][JWTSigner] Signer disabled
// DEBUG: [ENDPOINT: /private][JWTValidator] Roles will be matched against the key: 'roles'
Expand All @@ -116,7 +116,7 @@ func Example_HS256_cookie() {
_, signer, _ := krakendjose.NewSigner(sCfg, nil)
verifierCfg := newVerifierEndpointCfg("HS256", server.URL, []string{"role_a"})

externalTokenIssuer := func(rw http.ResponseWriter, req *http.Request) {
externalTokenIssuer := func(rw http.ResponseWriter, _ *http.Request) {
resp, _ := tokenIssuer(context.Background(), new(proxy.Request))
data, ok := resp.Data["access_token"]
if !ok {
Expand Down Expand Up @@ -270,16 +270,16 @@ func tokenIssuer(_ context.Context, _ *proxy.Request) (*proxy.Response, error) {
"sub": "1234567890qwertyuio",
"jti": "mnb23vcsrt756yuiomnbvcx98ertyuiop",
"roles": []string{"role_a", "role_b"},
"exp": 1735689600,
"exp": 2051882755,
},
"refresh_token": map[string]interface{}{
"aud": "http://api.example.com",
"iss": "http://example.com",
"sub": "1234567890qwertyuio",
"jti": "mnb23vcsrt756yuiomn12876bvcx98ertyuiop",
"exp": 1735689600,
"exp": 2051882755,
},
"exp": 1735689600,
"exp": 2051882755,
},
Metadata: proxy.Metadata{
StatusCode: 201,
Expand Down
12 changes: 6 additions & 6 deletions gin/jose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func TestTokenSignatureValidator(t *testing.T) {
propagateHeadersEndpointCfg := newVerifierEndpointCfg("RS256", server.URL, []string{})
propagateHeadersEndpointCfg.Endpoint = "/propagateheaders"

token := "eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTEtMDQtMjkifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.NrLwxZK8UhS6CV2ijdJLUfAinpjBn5_uliZCdzQ7v-Dc8lcv1AQA9cYsG63RseKWH9u6-TqPKMZQ56WfhqL028BLDdQCiaeuBoLzYU1tQLakA1V0YmouuEVixWLzueVaQhyGx-iKuiuFhzHWZSqFqSehiyzI9fb5O6Gcc2L6rMEoxQMaJomVS93h-t013MNq3ADLWTXRaO-negydqax_WmzlVWp_RDroR0s5J2L2klgmBXVwh6SYy5vg7RrnuN3S8g4oSicJIi9NgnG-dDikuaOg2DeFUt-mYq_j_PbNXf9TUl5hl4kEy7E0JauJ17d1BUuTl3ChY4BOmhQYRN0dYg"
token := "eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTEtMDQtMjkiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoyMDUxODgyNzU1LCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.u1fK05FpXctB-VkhhT3xu2WSIkEr1_VM71ald-yeKTesxhxg68TsHFEOBCgoXPuCviOP8QnUKNuVSeyMJh9z3nnrfQIjo9VZ2yicZu6ImYptSQ2DJbR80GDSPp-H7KnjaR9AAY0HZ0M-KUTaHdLABZFr307nkOeaJn_5jMpav7pqa7nrU3sI1CLX5pYVTggG6t7Zoqj2ebzzqdRxQEtdmZkD_NfH-3w3t-H0ylVdeBnPh-RvlspxC_mJzyUIJ0BwPlZpabppHm1ISySa4kwnwxEYnux0oZcb3PSoOZZZA467JySZ69PRlenNPdfGPL6E3uL1nqPHcxhte7ikSG4Q6Q"

dummyProxy := func(ctx context.Context, req *proxy.Request) (*proxy.Response, error) {
dummyProxy := func(_ context.Context, _ *proxy.Request) (*proxy.Response, error) {
return &proxy.Response{
Data: map[string]interface{}{
"aaaa": map[string]interface{}{
Expand Down Expand Up @@ -191,9 +191,9 @@ func TestCustomHeaderName(t *testing.T) {
nonDefaultAuthHeaderEndpointCfg.Endpoint = "/custom-header"
nonDefaultAuthHeaderEndpointCfg.ExtraConfig[jose.ValidatorNamespace].(map[string]interface{})["auth_header_name"] = "X-Custom-Auth"

token := "eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTEtMDQtMjkifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.NrLwxZK8UhS6CV2ijdJLUfAinpjBn5_uliZCdzQ7v-Dc8lcv1AQA9cYsG63RseKWH9u6-TqPKMZQ56WfhqL028BLDdQCiaeuBoLzYU1tQLakA1V0YmouuEVixWLzueVaQhyGx-iKuiuFhzHWZSqFqSehiyzI9fb5O6Gcc2L6rMEoxQMaJomVS93h-t013MNq3ADLWTXRaO-negydqax_WmzlVWp_RDroR0s5J2L2klgmBXVwh6SYy5vg7RrnuN3S8g4oSicJIi9NgnG-dDikuaOg2DeFUt-mYq_j_PbNXf9TUl5hl4kEy7E0JauJ17d1BUuTl3ChY4BOmhQYRN0dYg"
token := "eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTEtMDQtMjkiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoyMDUxODgyNzU1LCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.u1fK05FpXctB-VkhhT3xu2WSIkEr1_VM71ald-yeKTesxhxg68TsHFEOBCgoXPuCviOP8QnUKNuVSeyMJh9z3nnrfQIjo9VZ2yicZu6ImYptSQ2DJbR80GDSPp-H7KnjaR9AAY0HZ0M-KUTaHdLABZFr307nkOeaJn_5jMpav7pqa7nrU3sI1CLX5pYVTggG6t7Zoqj2ebzzqdRxQEtdmZkD_NfH-3w3t-H0ylVdeBnPh-RvlspxC_mJzyUIJ0BwPlZpabppHm1ISySa4kwnwxEYnux0oZcb3PSoOZZZA467JySZ69PRlenNPdfGPL6E3uL1nqPHcxhte7ikSG4Q6Q"

dummyProxy := func(ctx context.Context, req *proxy.Request) (*proxy.Response, error) {
dummyProxy := func(_ context.Context, _ *proxy.Request) (*proxy.Response, error) {
return &proxy.Response{
Data: map[string]interface{}{
"aaaa": map[string]interface{}{
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestCustomHeaderName(t *testing.T) {
func TestTokenSigner_error(t *testing.T) {
ts := TokenSigner(
func(_ *config.EndpointConfig, _ proxy.Proxy) gin.HandlerFunc {
return func(c *gin.Context) {
return func(_ *gin.Context) {
t.Error("the injected handler should not be called")
}
},
Expand All @@ -284,7 +284,7 @@ func TestTokenSigner_error(t *testing.T) {
func TestTokenSignatureValidator_error(t *testing.T) {
ts := TokenSignatureValidator(
func(_ *config.EndpointConfig, _ proxy.Proxy) gin.HandlerFunc {
return func(c *gin.Context) {
return func(_ *gin.Context) {
t.Error("the injected handler should not be called")
}
},
Expand Down
12 changes: 6 additions & 6 deletions mux/jose_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Example_RS256() {
// output:
// token request
// 201
// {"access_token":"eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMTEtMDQtMjkiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLC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ZU7KR3vJnH9ZNkgpUiu1XLfkpJ6tSuZXPLj5-Lxymr3Mf8PdWey5YjEfk6mN_xfBHZR_XZbwsVbiv_nWhp-qeltPkXraShEpsDFFfzjRFrGprFi1S00OFDBcObbmXtZ8GTyJgSN8vO_rU-vkt6no1phKHzuyaS5D6GdjrxDXv7pHYL-OWifBiElMs09PAd16rZy3-qSIDZS7vHo724cG9UYMgxSE86PvjGP_dOJCOf64p_wPkkBRw"}
// map[Content-Type:[application/json]]
// unauthorized request
// 401
Expand All @@ -57,7 +57,7 @@ func Example_HS256() {
// output:
// token request
// 201
// {"access_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.89zdRo4LCHpT93JX3_Yn2LoAOUvEAiFj6X7vnCgOd5Q","exp":1735689600,"refresh_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoxNzM1Njg5NjAwLCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uMTI4NzZidmN4OThlcnR5dWlvcCIsInN1YiI6IjEyMzQ1Njc4OTBxd2VydHl1aW8ifQ.lJuO1xyI8QOTWNGxBQe2hH90Jdp5y0DEbPd44I728dA"}
// {"access_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoyMDUxODgyNzU1LCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uYnZjeDk4ZXJ0eXVpb3AiLCJyb2xlcyI6WyJyb2xlX2EiLCJyb2xlX2IiXSwic3ViIjoiMTIzNDU2Nzg5MHF3ZXJ0eXVpbyJ9.xG6O62h475Y-EknyLFerPOUX6ATKCoIYEq4QsQsuw-Q","exp":2051882755,"refresh_token":"eyJhbGciOiJIUzI1NiIsImtpZCI6InNpbTIiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJodHRwOi8vYXBpLmV4YW1wbGUuY29tIiwiZXhwIjoyMDUxODgyNzU1LCJpc3MiOiJodHRwOi8vZXhhbXBsZS5jb20iLCJqdGkiOiJtbmIyM3Zjc3J0NzU2eXVpb21uMTI4NzZidmN4OThlcnR5dWlvcCIsInN1YiI6IjEyMzQ1Njc4OTBxd2VydHl1aW8ifQ.8rd0w9_H7Z_0J37nKvqQNwJnP25VrQcVAAa5sc3Fsw0"}
// map[Content-Type:[application/json]]
// unauthorized request
// 401
Expand All @@ -79,7 +79,7 @@ func Example_HS256_cookie() {
_, signer, _ := krakendjose.NewSigner(sCfg, nil)
verifierCfg := newVerifierEndpointCfg("HS256", server.URL, []string{"role_a"})

externalTokenIssuer := func(rw http.ResponseWriter, req *http.Request) {
externalTokenIssuer := func(rw http.ResponseWriter, _ *http.Request) {
resp, _ := tokenIssuer(context.Background(), new(proxy.Request))
data, ok := resp.Data["access_token"]
if !ok {
Expand Down Expand Up @@ -206,16 +206,16 @@ func tokenIssuer(_ context.Context, _ *proxy.Request) (*proxy.Response, error) {
"sub": "1234567890qwertyuio",
"jti": "mnb23vcsrt756yuiomnbvcx98ertyuiop",
"roles": []string{"role_a", "role_b"},
"exp": 1735689600,
"exp": 2051882755,
},
"refresh_token": map[string]interface{}{
"aud": "http://api.example.com",
"iss": "http://example.com",
"sub": "1234567890qwertyuio",
"jti": "mnb23vcsrt756yuiomn12876bvcx98ertyuiop",
"exp": 1735689600,
"exp": 2051882755,
},
"exp": 1735689600,
"exp": 2051882755,
},
Metadata: proxy.Metadata{
StatusCode: 201,
Expand Down
Loading

0 comments on commit 95ec430

Please sign in to comment.