From f9dfafa9d94191413d042fe1f240216d2157cbfd Mon Sep 17 00:00:00 2001 From: Roy <62500486+aazf@users.noreply.github.com> Date: Mon, 9 Jan 2023 00:26:14 +0300 Subject: [PATCH] Add device flow scope. (#616) add the openid as the base scope --- client/internal/oauth.go | 5 +++++ client/internal/oauth_test.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/client/internal/oauth.go b/client/internal/oauth.go index c80224212..ae327a620 100644 --- a/client/internal/oauth.go +++ b/client/internal/oauth.go @@ -56,6 +56,8 @@ type Hosted struct { Audience string // Hosted Native application client id ClientID string + // Hosted Native application request scope + Scope string // TokenEndpoint to request access token TokenEndpoint string // DeviceAuthEndpoint to request device authorization code @@ -68,6 +70,7 @@ type Hosted struct { type RequestDeviceCodePayload struct { Audience string `json:"audience"` ClientID string `json:"client_id"` + Scope string `json:"scope"` } // TokenRequestPayload used for requesting the auth0 token @@ -103,6 +106,7 @@ func NewHostedDeviceFlow(audience string, clientID string, tokenEndpoint string, return &Hosted{ Audience: audience, ClientID: clientID, + Scope: "openid", TokenEndpoint: tokenEndpoint, HTTPClient: httpClient, DeviceAuthEndpoint: deviceAuthEndpoint, @@ -119,6 +123,7 @@ func (h *Hosted) RequestDeviceCode(ctx context.Context) (DeviceAuthInfo, error) form := url.Values{} form.Add("client_id", h.ClientID) form.Add("audience", h.Audience) + form.Add("scope", h.Scope) req, err := http.NewRequest("POST", h.DeviceAuthEndpoint, strings.NewReader(form.Encode())) if err != nil { diff --git a/client/internal/oauth_test.go b/client/internal/oauth_test.go index fe22b1bac..3a9e2a0c2 100644 --- a/client/internal/oauth_test.go +++ b/client/internal/oauth_test.go @@ -59,9 +59,11 @@ func TestHosted_RequestDeviceCode(t *testing.T) { expectedAudience := "ok" expectedClientID := "bla" + expectedScope := "openid" form := url.Values{} form.Add("audience", expectedAudience) form.Add("client_id", expectedClientID) + form.Add("scope", expectedScope) expectPayload := form.Encode() testCase1 := test{ @@ -113,6 +115,7 @@ func TestHosted_RequestDeviceCode(t *testing.T) { hosted := Hosted{ Audience: expectedAudience, ClientID: expectedClientID, + Scope: expectedScope, TokenEndpoint: "test.hosted.com/token", DeviceAuthEndpoint: "test.hosted.com/device/auth", HTTPClient: &httpClient,