@@ -6,10 +6,14 @@ 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 TOKEN_COUNTER = Ref (0 )
13+ function id_token ()
14+ return string (TOKEN_COUNTER[] += 1 )
15+ end
16+
1317challenge_response_map = Dict ()
1418challenge_timeout = Dict ()
1519response_challenge_map = Dict ()
@@ -42,8 +46,8 @@ function response_handler(req)
4246 TOKEN[] = Dict (
4347 " user_name" => " firstname lastname" ,
4448 " user_email" => " [email protected] " ,
45- " id_token" => " full-" * ID_TOKEN ,
46- " access_token" => " full-" * ID_TOKEN ,
49+ " id_token" => " full-" * id_token () ,
50+ " access_token" => " full-" * id_token () ,
4751 " refresh_token" => refresh_token,
4852 " refresh_url" => " http://localhost:$(PORT) /auth/renew/token.toml/v2/" ,
4953 " expires_in" => EXPIRY,
@@ -89,8 +93,8 @@ function renew_handler(req)
8993
9094 TOKEN[][" refresh_token" ] = Random. randstring (10 )
9195 TOKEN[][" expires_at" ] = ceil (Int, time () + EXPIRY)
92- TOKEN[][" id_token" ] = " refresh-" * ID_TOKEN
93- TOKEN[][" access_token" ] = " refresh-" * ID_TOKEN
96+ TOKEN[][" id_token" ] = " refresh-" * id_token ()
97+ TOKEN[][" access_token" ] = " refresh-" * id_token ()
9498
9599 return HTTP. Response (200 , sprint (TOML. print, TOKEN[]))
96100end
@@ -167,11 +171,11 @@ function auth_device(req)
167171 end
168172 authenticated[device_code] = true
169173 refresh_token = Random. randstring (10 )
170- TOKEN[][" access_token" ] = " device-$ID_TOKEN "
174+ TOKEN[][" access_token" ] = " device-$( id_token ()) "
171175 TOKEN[][" token_type" ] = " bearer"
172176 TOKEN[][" expires_in" ] = EXPIRY
173177 TOKEN[][" refresh_token" ] = refresh_token
174- TOKEN[][" id_token" ] = " device-$ID_TOKEN "
178+ TOKEN[][" id_token" ] = " device-$( id_token ()) "
175179 return HTTP. Response (200 )
176180end
177181
0 commit comments