@@ -6,10 +6,17 @@ const CHALLENGE_EXPIRY = 10
66const PORT = 8888
77@enum AuthFlowMode CLASSIC_MODE DEVICE_FLOW_MODE DEVICE_FLOW_NO_SCOPE_MODE
88
9- const ID_TOKEN = Random. randstring (100 )
109const TOKEN = Ref (Dict ())
1110const MODE = Ref (CLASSIC_MODE)
1211
12+ const REQUEST_SET = Set ()
13+ # this counts the number of distinct authentication requests made against the server
14+ function id_token (key)
15+ push! (REQUEST_SET, key)
16+ token = length (REQUEST_SET)
17+ return string (token)
18+ end
19+
1320challenge_response_map = Dict ()
1421challenge_timeout = Dict ()
1522response_challenge_map = Dict ()
@@ -42,8 +49,8 @@ function response_handler(req)
4249 TOKEN[] = Dict (
4350 " user_name" => " firstname lastname" ,
4451 " user_email" => " [email protected] " ,
45- " id_token" => " full-" * ID_TOKEN ,
46- " access_token" => " full-" * ID_TOKEN ,
52+ " id_token" => " full-" * id_token (response) ,
53+ " access_token" => " full-" * id_token (response) ,
4754 " refresh_token" => refresh_token,
4855 " refresh_url" => " http://localhost:$(PORT) /auth/renew/token.toml/v2/" ,
4956 " expires_in" => EXPIRY,
@@ -89,8 +96,8 @@ function renew_handler(req)
8996
9097 TOKEN[][" refresh_token" ] = Random. randstring (10 )
9198 TOKEN[][" expires_at" ] = ceil (Int, time () + EXPIRY)
92- TOKEN[][" id_token" ] = " refresh-" * ID_TOKEN
93- TOKEN[][" access_token" ] = " refresh-" * ID_TOKEN
99+ TOKEN[][" id_token" ] = " refresh-" * id_token (auth)
100+ TOKEN[][" access_token" ] = " refresh-" * id_token (auth)
94101
95102 return HTTP. Response (200 , sprint (TOML. print, TOKEN[]))
96103end
@@ -167,11 +174,11 @@ function auth_device(req)
167174 end
168175 authenticated[device_code] = true
169176 refresh_token = Random. randstring (10 )
170- TOKEN[][" access_token" ] = " device-$ID_TOKEN "
177+ TOKEN[][" access_token" ] = " device-$( id_token (user_code)) "
171178 TOKEN[][" token_type" ] = " bearer"
172179 TOKEN[][" expires_in" ] = EXPIRY
173180 TOKEN[][" refresh_token" ] = refresh_token
174- TOKEN[][" id_token" ] = " device-$ID_TOKEN "
181+ TOKEN[][" id_token" ] = " device-$( id_token (user_code)) "
175182 return HTTP. Response (200 )
176183end
177184
0 commit comments