@@ -4,12 +4,11 @@ import Pkg: TOML
44const EXPIRY = 30
55const CHALLENGE_EXPIRY = 10
66const PORT = 8888
7- const LEGACY_MODE = 1
8- const DEVICE_FLOW_MODE = 2
7+ @enum AuthFlowMode CLASSIC_MODE DEVICE_FLOW_MODE DEVICE_FLOW_NO_SCOPE_MODE
98
109const ID_TOKEN = Random. randstring (100 )
1110const TOKEN = Ref (Dict ())
12- const MODE = Ref (LEGACY_MODE )
11+ const MODE = Ref (CLASSIC_MODE )
1312
1413challenge_response_map = Dict ()
1514challenge_timeout = Dict ()
@@ -102,29 +101,40 @@ function check_validity(req)
102101 return HTTP. Response (200 , payload == TOKEN[])
103102end
104103
105- function set_mode_legacy (req)
106- MODE[] = LEGACY_MODE
107- return HTTP. Response (200 )
108- end
109-
110- function set_mode_device (req)
111- MODE[] = DEVICE_FLOW_MODE
104+ function set_mode (req)
105+ global MODE
106+ mode = get (HTTP. getparams (req), " mode" , nothing )
107+ if mode == " classic"
108+ MODE[] = CLASSIC_MODE
109+ elseif mode == " device"
110+ MODE[] = DEVICE_FLOW_MODE
111+ elseif mode == " device-no-scope"
112+ MODE[] = DEVICE_FLOW_NO_SCOPE_MODE
113+ else
114+ return HTTP. Response (400 , " Invalid Mode $(mode) " )
115+ end
112116 return HTTP. Response (200 )
113117end
114118
115119function auth_configuration (req)
116- if MODE[] == LEGACY_MODE
117- return HTTP. Response (200 )
120+ global MODE
121+ if MODE[] == CLASSIC_MODE
122+ # classic mode could also return `auth_flows = ["classic"]`, but we choose to test
123+ # the legacy case where the configuration is not implemented at all (which also
124+ # implies the classic mode).
125+ return HTTP. Response (501 , " Not Implemented" )
118126 else
119- return HTTP. Response (
120- 200 ,
121- """ {
122- "auth_flows": ["classic", "device"],
123- "device_token_refresh_url": "http://localhost:$PORT /auth/renew/token.toml/device/",
124- "device_authorization_endpoint": "http://localhost:$PORT /auth/device/code",
125- "device_token_endpoint": "http://localhost:$PORT /auth/token"
126- } """ ,
127+ body = Dict (
128+ " auth_flows" => [" classic" , " device" ],
129+ " device_token_refresh_url" => " http://localhost:$PORT /auth/renew/token.toml/device/" ,
130+ " device_authorization_endpoint" => " http://localhost:$PORT /auth/device/code" ,
131+ " device_token_endpoint" => " http://localhost:$PORT /auth/token" ,
127132 )
133+ # device_token_scope omitted in DEVICE_FLOW_NO_SCOPE_MODE
134+ if MODE[] == DEVICE_FLOW_MODE
135+ body[" device_token_scope" ] = " openid"
136+ end
137+ return HTTP. Response (200 , JSON. json (body))
128138 end
129139end
130140
@@ -189,8 +199,7 @@ HTTP.register!(router, "POST", "/auth/device/code", auth_device_code)
189199HTTP. register! (router, " GET" , " /auth/device" , auth_device)
190200HTTP. register! (router, " POST" , " /auth/token" , auth_token)
191201HTTP. register! (router, " GET" , " /auth/renew/token.toml/device" , renew_handler)
192- HTTP. register! (router, " POST" , " /set_mode/legacy" , set_mode_legacy)
193- HTTP. register! (router, " POST" , " /set_mode/device" , set_mode_device)
202+ HTTP. register! (router, " POST" , " /set_mode/{mode}" , set_mode)
194203
195204function run ()
196205 println (" starting server" )
0 commit comments