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

Function TestDeviceTokenRequest

oauth2/oauth2_device_code_test.go:99–229  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func TestDeviceTokenRequest(t *testing.T) {
100 t.Parallel()
101
102 ctx := context.Background()
103 reg := testhelpers.NewRegistryMemory(t)
104 testhelpers.NewOAuth2Server(ctx, t, reg)
105
106 secret := uuid.New()
107 c := &client.Client{
108 ID: "device-client",
109 Secret: secret,
110 GrantTypes: []string{
111 string(fosite.GrantTypeDeviceCode),
112 string(fosite.GrantTypeRefreshToken),
113 },
114 Scope: "hydra offline openid",
115 Audience: []string{"https://api.ory.sh/"},
116 }
117 require.NoError(t, reg.ClientManager().CreateClient(ctx, c))
118
119 oauthClient := &oauth2.Config{
120 ClientID: c.GetID(),
121 ClientSecret: secret,
122 Endpoint: oauth2.Endpoint{
123 DeviceAuthURL: reg.Config().OAuth2DeviceAuthorisationURL(ctx).String(),
124 TokenURL: reg.Config().OAuth2TokenURL(ctx).String(),
125 AuthStyle: oauth2.AuthStyleInHeader,
126 },
127 Scopes: strings.Split(c.Scope, " "),
128 }
129
130 testCases := []struct {
131 description string
132 setUp func(signature, userCodeSignature string)
133 check func(t *testing.T, token *oauth2.Token, err error)
134 cleanUp func()
135 }{
136 {
137 description: "should pass with refresh token",
138 setUp: func(signature, userCodeSignature string) {
139 authreq := &fosite.DeviceRequest{
140 UserCodeState: fosite.UserCodeAccepted,
141 Request: fosite.Request{
142 Client: &fosite.DefaultClient{
143 ID: c.GetID(),
144 GrantTypes: []string{string(fosite.GrantTypeDeviceCode)},
145 },
146 RequestedScope: []string{"hydra", "offline"},
147 GrantedScope: []string{"hydra", "offline"},
148 Session: &hydraoauth2.Session{
149 DefaultSession: &openid.DefaultSession{
150 Claims: &jwt.IDTokenClaims{
151 Subject: "hydra",
152 },
153 ExpiresAt: map[fosite.TokenType]time.Time{
154 fosite.DeviceCode: time.Now().Add(time.Hour).UTC(),
155 },
156 },

Callers

nothing calls this directly

Calls 15

GetIDMethod · 0.95
NewRegistryMemoryFunction · 0.92
NewOAuth2ServerFunction · 0.92
OAuth2TokenURLMethod · 0.80
checkMethod · 0.80
CreateClientMethod · 0.65
ClientManagerMethod · 0.65
StringMethod · 0.65
ConfigMethod · 0.65
AddMethod · 0.65
NowMethod · 0.65

Tested by

no test coverage detected