Extracting ACCESS_TOKEN from Instagram redirect with Angular 5(Implicit Authentication)

时光怂恿深爱的人放手 提交于 2020-01-16 17:59:54

问题


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


回答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].

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

declare let window;


来源:https://stackoverflow.com/questions/50193610/extracting-access-token-from-instagram-redirect-with-angular-5implicit-authenti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!