Skip to content

Commit e82dd3e

Browse files
committed
fix: fetch token scope from discovery endpoint
1 parent 3e66ca1 commit e82dd3e

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PkgAuthentication"
22
uuid = "4722fa14-9d28-45f9-a1e2-a38605bd88f0"
33
authors = ["Sebastian Pfitzner", "contributors"]
4-
version = "2.2.0"
4+
version = "2.2.1"
55

66
[deps]
77
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

docs/auth-flows.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,31 @@ When device authentication is not supported by the server the response body MAY
106106
}
107107
```
108108

109+
If the `auth_flows` property is present, it MUST be an array of strings.
110+
If it is missing, it is assumed to have the value `["classic"]`.
111+
109112
In this case, PkgAuthentication will execute the Classic Authentication Flow.
110113

111-
When device authentication _is_ supported by the server, the response body MUST contain:
114+
When device authentication _is_ supported by the server, the response body MUST contain the `auth_flows` property, and the array MUST contain the value `device`.
115+
Additionally, the response body MUST contain the following properties:
116+
117+
- `device_authorization_endpoint`: URL to be used to initiate the device authentication flow.
118+
- `device_token_endpoint`: URL to be used to exchange the device code for a token.
119+
- `device_token_refresh_url`: URL that can be used to refresh the token.
120+
121+
Furthermore, the response body MAY contain the following properties:
122+
123+
- `device_token_scope`: Scope to be used when requesting a token. If missing, the scope will be omitted from the device token request.
124+
125+
An example of a possible valid response body:
112126

113127
```json
114128
{
115129
"auth_flows": ["classic", "device"],
116130
"device_token_refresh_url": "https://juliahub.com/auth/renew/token.toml/device/",
117131
"device_authorization_endpoint": "https://auth.juliahub.com/auth/device/code",
118-
"device_token_endpoint": "https://auth.juliahub.com/auth/token"
132+
"device_token_endpoint": "https://auth.juliahub.com/auth/token",
133+
"device_token_scope": "openid email profile offline_access"
119134
}
120135
```
121136

src/PkgAuthentication.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ end
248248

249249
function step(state::NoAuthentication)::Union{RequestLogin, Failure}
250250
auth_config = get_auth_configuration(state)
251+
scope = get(auth_config, "device_token_scope", nothing)
251252
success, challenge, body_or_response = if "device" in get(auth_config, "auth_flows", [])
252-
fetch_device_code(state, auth_config["device_authorization_endpoint"])
253+
fetch_device_code(state, auth_config["device_authorization_endpoint"], scope)
253254
else
254255
initiate_browser_challenge(state)
255256
end
@@ -267,14 +268,14 @@ function step(state::NoAuthentication)::Union{RequestLogin, Failure}
267268
end
268269
end
269270

270-
function fetch_device_code(state::NoAuthentication, device_endpoint::AbstractString)
271+
function fetch_device_code(state::NoAuthentication, device_endpoint::AbstractString, device_scope::Union{AbstractString, Nothing})
271272
output = IOBuffer()
272273
response = Downloads.request(
273274
device_endpoint,
274275
method = "POST",
275276
input = device_token_request_body(
276277
client_id = device_client_id(),
277-
scope = "openid profile offline_access",
278+
scope = device_scope,
278279
),
279280
output = output,
280281
throw = false,

0 commit comments

Comments
 (0)