使用Angular 5(隐式身份验证)从Instagram重定向中提取ACCESS_TOKEN [英] Extracting ACCESS_TOKEN from Instagram redirect with Angular 5(Implicit Authentication)

查看:123
本文介绍了使用Angular 5(隐式身份验证)从Instagram重定向中提取ACCESS_TOKEN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我正在开发一个没有后端的纯前端应用程序,因此我将使用Instagram隐式身份验证.问题是,在用户授权应用程序后,Instagram会使用http://your-redirect-uri#access_token=ACCESS-TOKEN这样的访问令牌重定向到我的redirect_uri.如何从中提取访问令牌?我尝试使用路由器,但使用'#'失败

Since I'm developing a pure frontend app with no backend, I'm going with Instagram implicit authentication. The problem is, after the user authorizes the app, Instagram redirects to my redirect_uri with the access token like this, http://your-redirect-uri#access_token=ACCESS-TOKEN. How do I extract the access token from this? I tried using the router but with '#' it was not successful

推荐答案

使用window.location.hash访问所有以#开头的参数. 或者,您可以使用window.location.href访问完整的URL. 要获取令牌,可以使用window.location.hash.match(/#access_token=([^&]+)/)[1].

Use window.location.hash to access to all parameters starting from #. Or you can use window.location.href to access full URL. To get the token you can use window.location.hash.match(/#access_token=([^&]+)/)[1].

注意:如果您使用的是TypeScript,则需要在组件中导入窗口.

Note: If you are using TypeScript then you'd need to import window in your component.

declare let window;

这篇关于使用Angular 5(隐式身份验证)从Instagram重定向中提取ACCESS_TOKEN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆