(t *testing.T)
| 97 | } |
| 98 | |
| 99 | func 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 | }, |
nothing calls this directly
no test coverage detected