小编Geo*_*y D的帖子

typescript - 等待一个observable/promise完成,并返回observable

我对Typescript和RxJS很安静,我尝试返回一个observable,而不是其他observable完成:

public myObservable = () : Observable<boolean> => {
    console.log('retrieving the token in DB');
    return Observable.create(observer => {
        setTimeout(() => {
            observer.next(true);
            observer.complete();
        }, 5000);
    });
}

public makeRequest = (): Observable<any> => {
    return this.myObservable().subscribe(
        function (x) {
            console.log('I have the token, now I can make the HTTP call');

            return this.http.get('http://jsonplaceholder.typicode.com/posts/1')
                .map( (responseData) => {
                    return responseData.json();
                })
                .map((item:any) => {
                    return {
                        id: item.id,
                        userId: item.userId,
                        title: item.title,
                        body: item.body
                    };
                });

        },
        function (err) {
            console.error('Error: ' …
Run Code Online (Sandbox Code Playgroud)

observable rxjs typescript

31
推荐指数
2
解决办法
7万
查看次数

如何在客户端处理访问令牌和刷新令牌

我正在使用AngularJS客户端创建一个网站,并在REST中与后端(在另一个域中)进行通信。

为了验证每个调用,我通过每个HTTPS调用的标头传递一个令牌:“授权:承载access_tokenXXXXXX”

当令牌过期时,由于refresh_token,我能够创建一个新令牌。

access_token和refresh_token需要存储在客户端,因为浏览器需要在HTTP请求标头中将其设置为明文形式。

我的问题是:

问题1:建议使用哪种方式存储access_token和refresh_token以使其对浏览器可用,从而使其相对安全?(我有安静的敏感数据,例如个人照片)

问题2:access_token和refresh_token的建议生存期(=无法使用之前的时间)是多少?(仅供参考,我会在401响应后刷新令牌,并且我的应用是社交应用)

问题3:我有建筑方面的问题吗?我是否应该更改它以便根本不使用JavaScript并使用仅HTTP的cookie?

谢谢 :)

杰弗里

更新:

我最终选择了仅HTTP cookie。我正在使用Django Oauth Toolkit,因此Django正在等待HTTP标头(而不是Cookie)中的授权。

为了解决这个问题,我正在使用一个中间件,该中间件收集cookie的令牌并将其设置在标题中。它还应该允许我在access_token过期之前重新验证用户身份(使用刷新令牌)。

browser security restful-authentication access-token

5
推荐指数
1
解决办法
5017
查看次数