Add device flow scope. (#616)

add the openid as the base scope
This commit is contained in:
Roy 2023-01-09 00:26:14 +03:00 committed by GitHub
parent ca62f6787a
commit f9dfafa9d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -56,6 +56,8 @@ type Hosted struct {
Audience string Audience string
// Hosted Native application client id // Hosted Native application client id
ClientID string ClientID string
// Hosted Native application request scope
Scope string
// TokenEndpoint to request access token // TokenEndpoint to request access token
TokenEndpoint string TokenEndpoint string
// DeviceAuthEndpoint to request device authorization code // DeviceAuthEndpoint to request device authorization code
@ -68,6 +70,7 @@ type Hosted struct {
type RequestDeviceCodePayload struct { type RequestDeviceCodePayload struct {
Audience string `json:"audience"` Audience string `json:"audience"`
ClientID string `json:"client_id"` ClientID string `json:"client_id"`
Scope string `json:"scope"`
} }
// TokenRequestPayload used for requesting the auth0 token // TokenRequestPayload used for requesting the auth0 token
@ -103,6 +106,7 @@ func NewHostedDeviceFlow(audience string, clientID string, tokenEndpoint string,
return &Hosted{ return &Hosted{
Audience: audience, Audience: audience,
ClientID: clientID, ClientID: clientID,
Scope: "openid",
TokenEndpoint: tokenEndpoint, TokenEndpoint: tokenEndpoint,
HTTPClient: httpClient, HTTPClient: httpClient,
DeviceAuthEndpoint: deviceAuthEndpoint, DeviceAuthEndpoint: deviceAuthEndpoint,
@ -119,6 +123,7 @@ func (h *Hosted) RequestDeviceCode(ctx context.Context) (DeviceAuthInfo, error)
form := url.Values{} form := url.Values{}
form.Add("client_id", h.ClientID) form.Add("client_id", h.ClientID)
form.Add("audience", h.Audience) form.Add("audience", h.Audience)
form.Add("scope", h.Scope)
req, err := http.NewRequest("POST", h.DeviceAuthEndpoint, req, err := http.NewRequest("POST", h.DeviceAuthEndpoint,
strings.NewReader(form.Encode())) strings.NewReader(form.Encode()))
if err != nil { if err != nil {

View File

@ -59,9 +59,11 @@ func TestHosted_RequestDeviceCode(t *testing.T) {
expectedAudience := "ok" expectedAudience := "ok"
expectedClientID := "bla" expectedClientID := "bla"
expectedScope := "openid"
form := url.Values{} form := url.Values{}
form.Add("audience", expectedAudience) form.Add("audience", expectedAudience)
form.Add("client_id", expectedClientID) form.Add("client_id", expectedClientID)
form.Add("scope", expectedScope)
expectPayload := form.Encode() expectPayload := form.Encode()
testCase1 := test{ testCase1 := test{
@ -113,6 +115,7 @@ func TestHosted_RequestDeviceCode(t *testing.T) {
hosted := Hosted{ hosted := Hosted{
Audience: expectedAudience, Audience: expectedAudience,
ClientID: expectedClientID, ClientID: expectedClientID,
Scope: expectedScope,
TokenEndpoint: "test.hosted.com/token", TokenEndpoint: "test.hosted.com/token",
DeviceAuthEndpoint: "test.hosted.com/device/auth", DeviceAuthEndpoint: "test.hosted.com/device/auth",
HTTPClient: &httpClient, HTTPClient: &httpClient,