Skip to content

Commit

Permalink
feat: support verification_url workaround for DeviceAuthorizationResp…
Browse files Browse the repository at this point in the history
…onse unmarshal
  • Loading branch information
celian-garcia committed Apr 3, 2024
1 parent 5cdb65c commit 200d98c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/oidc/device_authorization.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package oidc

import "encoding/json"

// DeviceAuthorizationRequest implements
// https://www.rfc-editor.org/rfc/rfc8628#section-3.1,
// 3.1 Device Authorization Request.
Expand All @@ -20,6 +22,26 @@ type DeviceAuthorizationResponse struct {
Interval int `json:"interval,omitempty"`
}

func (resp *DeviceAuthorizationResponse) UnmarshalJSON(data []byte) error {
type Alias DeviceAuthorizationResponse
aux := &struct {

Check warning on line 27 in pkg/oidc/device_authorization.go

View check run for this annotation

Codecov / codecov/patch

pkg/oidc/device_authorization.go#L25-L27

Added lines #L25 - L27 were not covered by tests
// workaround misspelling of verification_uri
// https://stackoverflow.com/q/76696956/5690223
// https://developers.google.com/identity/protocols/oauth2/limited-input-device?hl=fr#success-response
VerificationURL string `json:"verification_url"`
*Alias
}{
Alias: (*Alias)(resp),

Check warning on line 34 in pkg/oidc/device_authorization.go

View check run for this annotation

Codecov / codecov/patch

pkg/oidc/device_authorization.go#L31-L34

Added lines #L31 - L34 were not covered by tests
}
if err := json.Unmarshal(data, &aux); err != nil {
return err

Check warning on line 37 in pkg/oidc/device_authorization.go

View check run for this annotation

Codecov / codecov/patch

pkg/oidc/device_authorization.go#L36-L37

Added lines #L36 - L37 were not covered by tests
}
if resp.VerificationURI == "" {
resp.VerificationURI = aux.VerificationURL

Check warning on line 40 in pkg/oidc/device_authorization.go

View check run for this annotation

Codecov / codecov/patch

pkg/oidc/device_authorization.go#L39-L40

Added lines #L39 - L40 were not covered by tests
}
return nil

Check warning on line 42 in pkg/oidc/device_authorization.go

View check run for this annotation

Codecov / codecov/patch

pkg/oidc/device_authorization.go#L42

Added line #L42 was not covered by tests
}

// DeviceAccessTokenRequest implements
// https://www.rfc-editor.org/rfc/rfc8628#section-3.4,
// Device Access Token Request.
Expand Down

0 comments on commit 200d98c

Please sign in to comment.