在快速应用程序中解析URL哈希片段

在快速应用程序中解析URL哈希片段

本文介绍了在快速应用程序中解析URL哈希片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个快速应用程序,我必须使用oauth 2.0流程对用户进行身份验证.我已成功将用户重定向到oauth提供程序,并且该提供程序在oauth回调中发送了访问令牌.像

I am writing a express application, and I have to authenticate the user using oauth 2.0 flow. I have successfully redirected the user to the oauth provider and the provider send the access token in the oauth callback. Something like

http://localhost:4000/oauth/callback#access_token=<token>

现在我有一个像这样的快速路由处理程序

Now I have a express route handler like

app.get('/oauth/callback', function(req, res, next) {
});

我知道哈希片段不会传递到服务器,但这是一个oauth回调.

I know that hash fragment is not passed to server, but this is a oauth callback.

如何在路由处理程序中获取url哈希片段?

How can I get the url hash fragment in the route handler ?

推荐答案

我为满足目标而努力.

不幸的是,目前这是我们的OAuth回调的工作方式,并且我们不发送回查询字符串参数.我已经提到并讨论了这一点,我们将在某个时候解决此问题,但目前尚无确切的时间表.

Unfortunately at the moment this is the way our OAuth callback works, and we don't send back a query string parameter. I've mentioned and discussed this and we'll fix this at some point but we have no exact time frame for now.

目前,您能做的最好的事情就是从您的快速应用程序中提供一个纯HTML页面,该页面具有一些javascript,它将从window.location.hash中提取令牌,然后向您的/oauth/callback发出请求? access_token =令牌端点.

The best thing you can do at the moment is to serve a plain HTML page from your express app that has some javascript that will extract the token from window.location.hash and then make a request to your /oauth/callback?access_token=token endpoint.

这篇关于在快速应用程序中解析URL哈希片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 15:06