Ember-Simple-Auth currentUser需要示例帮助 [英] Ember-Simple-Auth currentUser example help required

查看:97
本文介绍了Ember-Simple-Auth currentUser需要示例帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我意识到这里的帐户示例: https://github.com/simplabs/ember-simple-auth/blob/8863c032fcea6148a5b3365be5d66dc2389d301d/examples/4-authenticated-account.html



提供检索当前登录帐户的代码。我刚刚提出了一些关于这个例子的问题,因为我试图让它在Ember-CLI应用程序中工作。



SimpleAuth 在示例中被使用,但是,我不知道从哪里来,因为我试图从$ 导入SimpleAuth从... 但我不知道什么文件从中导入。



此外,我想知道服务器的响应是否现在需要返回user_id以及access_token / refresh_token?



如果是这样,那oauth是否兼容?



编辑:我目前的代码

  // app / initializers / oauth-custom.js 
导入Ember from'ember';
从'front / authenticators / oauth-custom'导入OAuthCustomAuthenticator;
import from'simple-auth / session';


export default {
name:'oauth-custom',
before:'simple-auth',

initialize:function (容器){
Session.reopen({
currentUser:function(){
var user_id = this.get('user_id');
if(!Ember.isEmpty user_id))$ {
}返回container.lookup('store:main')find('user',user_id);
}
} .property('user_id')
});
container.register(
'oauth-custom:oauth2-password-grant',
OAuthCustomAuthenticator
);
}
};

身份验证完美无缺,只是我看不到任何呼叫/用户/ id尝试制作。



服务器的响应示例:

  
access_token:asdf,
token_type:承载,
expires:1406082157,
expires_in:604800,
refresh_token :asdf,
user_id:1
}


解决方案

SimpleAuth全局只在库的浏览器分发中定义。当您使用ember-cli时,您可以导入各个组件,而不是通过全局访问它们(参见例如: http://log.simplabs.com/post/90339547725/using-ember-simple-auth-with-ember-cli )。 p>

得到你会这样做的会话:

  import'from a simple / auth / session' 

Session.reopen({
...
});

上面链接的示例要求服务器包含 user_id 在不符合OAuth 2.0规范的响应中进行定制。如果您想/需要符合要求,您可以获得当前用户通过 GET / me 或sth。一旦会话被认证就可以了。


So I realize that the account example here: https://github.com/simplabs/ember-simple-auth/blob/8863c032fcea6148a5b3365be5d66dc2389d301d/examples/4-authenticated-account.html

Provides the code for retrieving the currently logged in account. I just have a few questions about the example as I am trying to get it working in an Ember-CLI app.

SimpleAuth is being used in the example however, I don't know where it's coming from as I am trying to import SimpleAuth from ... but I don't know what file to import it from.

Furthermore, I am wondering if the response from the server now needs to return the user_id as well with the access_token/refresh_token?

If so, is that oauth compatible?

EDIT: My current code

// app/initializers/oauth-custom.js
import Ember from 'ember';
import OAuthCustomAuthenticator from 'front/authenticators/oauth-custom';
import Session from 'simple-auth/session';


export default {
    name: 'oauth-custom',
    before: 'simple-auth',

    initialize: function(container) {
        Session.reopen({
            currentUser: function() {
                var user_id = this.get('user_id');
                if (!Ember.isEmpty(user_id)) {
                    return container.lookup('store:main').find('user', user_id);
                }
            }.property('user_id')
        });
        container.register(
            'oauth-custom:oauth2-password-grant',
            OAuthCustomAuthenticator
        );
    }
};

Authentication works out perfectly, it's just that I don't see any call /user/id that ember tries to make.

Sample response from the server:

{
    "access_token": "asdf",
    "token_type": "bearer",
    "expires": 1406082157,
    "expires_in": 604800,
    "refresh_token": "asdf",
    "user_id": "1"
}

解决方案

The SimpleAuth global is only defined in the browserified distribution of the library. When you're using ember-cli you import the individual components instead of accessing them via the global (see e.g. this example: http://log.simplabs.com/post/90339547725/using-ember-simple-auth-with-ember-cli).

To e.g. get the session you'd do sty like:

import Session from 'simple-auth/session';

Session.reopen({
  …
});

The example linked above requires the server to include the user_id in the response which is not compliant with the OAuth 2.0 specification but a customization. If you want/need to be compliant you could get the current user e.g. via a GET /me or sth. like that once the session is authenticated.

这篇关于Ember-Simple-Auth currentUser需要示例帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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