这可能是一个新手问题,但我在SO或Okta论坛/指南上找不到任何答案。我已将我的Okta应用程序配置为在用户登录并同意范围时重定向到https://localhost:443/auth/callback
。我正在使用隐式授予,并且重定向有效,但是在我的/auth/callback
中,请求查询,标头和正文不包含访问令牌。只有当我致电res.end()
时Express才会重定向到以下URL:
https://localhost/auth/callback#access_token=accessTokenHere&token_type=Bearer&expires_in=3600&scope=openid+phone&state=myState
如何检索访问令牌?我的快递路线:
router.get('/auth/callback', (req, res) => {
console.log(req.headers); // no access token here
console.log(req.body); // {}
console.log(req.body); // {}
res.end(); // redirects to https://localhost/auth/callback#access_token=accessTokenHere&token_type=Bearer&expires_in=3600&scope=openid+phone&state=myState
});
答案 0 :(得分:0)
这是因为,URL中#
之后的内容称为URI fragment identifier
,它不会被发送到浏览器中使用的服务器,并且可以通过window.location.hash
进行访问< / p>
您可以使用#
(可以通过?
访问)来代替query parameters
,并使用req.query.query_name
(并保留后面的部分)。 query_name
是access_token,token_type,expires_in ...
答案 1 :(得分:0)
[responseMode] [1]
[1]:https://github.com/okta/okta-auth-js#responsemode-1可以设置为以下值之一:fragment,form_post,query或okta_post_message。 参考:https://developer.okta.com/docs/reference/api/oidc/#request-parameters