简体   繁体   English

angularjs-建立一个登录/启动板,重定向到新应用,但维护令牌信息

[英]angularjs - building a login/launchpad that redirects to new app but maintains token info

So far i have on localhost/app1 the main.html page with app.js set up. 到目前为止,我已经在localhost/app1上设置了app.jsmain.html页面。 Inside the main.html i have an a tag that goes to localhost/app2 . main.html我有一个转到localhost/app2 a标签。 The app.js contains a generated JWT token (eg: containing login or user information). app.js包含一个生成的JWT令牌(例如:包含登录名或用户信息)。 The question is, how can i acces the JWT token on the app2 angularjs application. 问题是,如何在app2 angularjs应用程序上访问JWT令牌。 Using cookies to store the token? 使用Cookie来存储令牌? Don't like to use cookies with JWT token style authentication, and don't like to nest app2 inside app1 or load it dynamicly if i make app3 for example. 不喜欢将cookie与JWT令牌样式身份验证一起使用,也不喜欢将app2嵌套在app1或者例如如果我将app3制作成动态加载它。

Right now I'm saving the token with $window.sessionStorage and then referencing from app2 the app.js (calling the module), which works, but is that the correct way to do it? 现在,我使用$window.sessionStorage保存令牌,然后从app2引用app.js (调用模块),该方法有效,但这是正确的方法吗? Also any global variables that are set on app.js are undefined on app2.js , should they be inside $window.sessionStorage too? 另外,在app.js上设置的所有全局变量在app2.js上均未定义,它们是否也应该在$window.sessionStorage


ps Beginner regarding anguarjs and specially this having multiple angularjs apps sharing data :) ps关于anguarjs的初学者,特别是这有多个angularjs应用共享数据:)

First, anything that you want to put into the second app does need to be serialized and "saved" in some way. 首先,您想要放入第二个应用程序的所有内容都需要以某种方式进行序列化和“保存”。 You can use session storage, local storage or cookies for this task. 您可以将会话存储,本地存储或cookie用于此任务。

The downside to session storage is that it doesn't stick between tabs or in some cases during a refresh of the window. 会话存储的不利之处在于,它不会卡在选项卡之间,或者在某些情况下不会刷新窗口。

Also, you may want to use a library to abstract session storage or local storage. 另外,您可能想使用库来抽象会话存储或本地存储。 I have been using https://github.com/agrublev/angularLocalStorage for my app. 我一直在为我的应用程序使用https://github.com/agrublev/angularLocalStorage

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM