| 1 |
package oidc |
| 2 |
|
| 3 |
import "encoding/json" |
| 4 |
|
| 5 |
// DeviceAuthorizationRequest implements |
| 6 |
// https://www.rfc-editor.org/rfc/rfc8628#section-3.1, |
| 7 |
// 3.1 Device Authorization Request. |
| 8 |
type DeviceAuthorizationRequest struct { |
| 9 |
Scopes SpaceDelimitedArray `schema:"scope"` |
| 10 |
ClientID string `schema:"client_id"` |
| 11 |
|
| 12 |
// DPoPJKT is the `dpop_jkt` parameter defined by OpenID Connect Key |
| 13 |
// Binding 1.0, Section 3.1. It carries the RFC 7638 JWK SHA-256 |
| 14 |
// Thumbprint of the client's proof-of-possession public key and, |
| 15 |
// together with the `bound_key` scope, requests a key-bound ID Token. |
| 16 |
// |
| 17 |
// Experimental: OpenID Connect Key Binding 1.0 is a draft standard. |
| 18 |
// This API may change or be removed without a major version bump. |
| 19 |
DPoPJKT string `schema:"dpop_jkt,omitempty"` |
| 20 |
} |
| 21 |
|
| 22 |
// DeviceAuthorizationResponse implements |
| 23 |
// https://www.rfc-editor.org/rfc/rfc8628#section-3.2 |
| 24 |
// 3.2. Device Authorization Response. |
| 25 |
type DeviceAuthorizationResponse struct { |
| 26 |
DeviceCode string `json:"device_code"` |
| 27 |
UserCode string `json:"user_code"` |
| 28 |
VerificationURI string `json:"verification_uri"` |
| 29 |
VerificationURIComplete string `json:"verification_uri_complete,omitempty"` |
| 30 |
ExpiresIn int `json:"expires_in"` |
| 31 |
Interval int `json:"interval,omitempty"` |
| 32 |
} |
| 33 |
|
| 34 |
func (resp *DeviceAuthorizationResponse) UnmarshalJSON(data []byte) error { |
| 35 |
type Alias DeviceAuthorizationResponse |
| 36 |
aux := &struct { |
| 37 |
// workaround misspelling of verification_uri |
| 38 |
// https://stackoverflow.com/q/76696956/5690223 |
| 39 |
// https://developers.google.com/identity/protocols/oauth2/limited-input-device?hl=fr#success-response |
| 40 |
VerificationURL string `json:"verification_url"` |
| 41 |
*Alias |
| 42 |
}{ |
| 43 |
Alias: (*Alias)(resp), |
| 44 |
} |
| 45 |
if err := json.Unmarshal(data, &aux); err != nil { |
| 46 |
return err |
| 47 |
} |
| 48 |
if resp.VerificationURI == "" { |
| 49 |
resp.VerificationURI = aux.VerificationURL |
| 50 |
} |
| 51 |
return nil |
| 52 |
} |
| 53 |
|
| 54 |
// DeviceAccessTokenRequest implements |
| 55 |
// https://www.rfc-editor.org/rfc/rfc8628#section-3.4, |
| 56 |
// Device Access Token Request. |
| 57 |
type DeviceAccessTokenRequest struct { |
| 58 |
GrantType GrantType `json:"grant_type" schema:"grant_type"` |
| 59 |
DeviceCode string `json:"device_code" schema:"device_code"` |
| 60 |
} |