标签: ember-simple-auth

Ember-simple-auth,Torii和Facebook Oauth2的工作流程

我之前关于ember-simple-auth和torii的问题之后,我使用他们的Facebook帐户成功验证了我的用户.

但目前,torii的提供商facebook-oauth2正在从Facebook返回授权码; 当承诺解决时,我将此授权代码发送到我的后端,在那里我执行针对Facebook的请求以获取用户的ID和电子邮件:然后我在我的后端验证用户,生成特定的访问令牌并发送回我的ember应用程序.

客户代码:

// app/controllers/login.js
import Ember from 'ember';
import LoginControllerMixin from 'simple-auth/mixins/login-controller-mixin';

export
default Ember.Controller.extend(LoginControllerMixin, {
    // This authenticator for a simple login/password authentication.
    authenticator: 'simple-auth-authenticator:oauth2-password-grant',
    actions: {
        // This method for login with Facebook.
        authenticateWithFacebook: function() {
            var _this = this;
            this.get('session').authenticate(
                'simple-auth-authenticator:torii',
                "facebook-oauth2"
            ).then(
                function() {
                    var authCode = _this.get('session.authorizationCode');
                    Ember.$.ajax({
                            type: "POST",
                            url: window.ENV.host + "/facebook/auth.json",
                            data: JSON.stringify({
                                    auth_code: authCode
                            }),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function(data) {
                                    // TODO : manage …
Run Code Online (Sandbox Code Playgroud)

authentication facebook ember.js ember-simple-auth

17
推荐指数
1
解决办法
4033
查看次数

Ember Simple Auth:会话在刷新时丢失

我在Ember-cli应用程序中使用Ember Simple Auth Devise v 0.6.4.

我可以正常登录,但是当我刷新页面时会话丢失.(在Firefox和Chrome中测试过.)

登录后,检查localStorage会显示会话,刷新localStorage后为空.

这是我登录时本地存储中的内容:

在此输入图像描述

ember.js ember-simple-auth

10
推荐指数
1
解决办法
4187
查看次数

CORS预检频道没有成功

我正在尝试使用PHP REST框架构建一个Ember应用程序作为我的api本地.Ember应用程序正在服务,http://localhost:4200api正在服务http://localhost.这导致了CORS问题.我已经尝试了我能想到的所有内容,但我一直收到错误,说请求被阻止,预检频道没有成功.它在Firefox或Chrome中无法成功.

我已将以下内容添加到.htaccess我的api文件中:

Header set Access-Control-Allow-Methods "GET, POST, OPTIONS"
Header set Access-Control-Allow-Origin "http://localhost:4200"
Header set Access-Control-Allow-Credentials true
Header set Access-Control-Allow-Headers "accept, content-type"
Run Code Online (Sandbox Code Playgroud)

这是我的请求标题:

Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://localhost:4200
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Run Code Online (Sandbox Code Playgroud)

响应头:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: accept, content-type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: http://localhost:4200
Connection: close
Content-Type: text/html; charset=utf-8
Date: Fri, 24 Jul …
Run Code Online (Sandbox Code Playgroud)

cross-domain cors ember.js ember-simple-auth

9
推荐指数
2
解决办法
8933
查看次数

Ember Simple Auth - 将当前用户注入每条路线

我正在使用Ember Simple Auth构建一个站点.

我按照这些说明尝试将当前用户对象添加到会话中并使用这个略微适应的代码工作:

import Ember from 'ember';
import Session from 'simple-auth/session';

export default {
  name: "current-user",
  before: "simple-auth",
  initialize: function(container) {
    Session.reopen({
      setCurrentUser: function() {
        var accessToken = this.get('secure.token');
        var _this = this;
        if (!Ember.isEmpty(accessToken)) {
          return container.lookup('store:main').find('user', 'me').then(function(user) {
            _this.set('content.currentUser', user);
          });
        }
      }.observes('secure.token'),
      setAccount: function() {
        var _this = this;
        return container.lookup('store:main').find('account', this.get('content.currentUser.account.content.id')).then(function(account) {
          _this.set('content.account', account);
        });
      }.observes('content.currentUser'),
    });
  }
};
Run Code Online (Sandbox Code Playgroud)

但是,使用最新版本的Ember我得到以下内容:

弃用:lookup在登记处被召集.该initializerAPI不再接收一个容器,你应该使用一个instanceInitializer从容器中查找对象.有关详细信息,请参阅http://emberjs.com/guides/deprecations#toc_deprecate-access-to-instances-in-initializers.

我知道我需要将上面的内容拆分为/ app/initializers和/ app/instance-initializers(根据这里 …

dependency-injection ember.js ember-simple-auth

8
推荐指数
2
解决办法
4194
查看次数

身份验证后,Ember Simple Auth会进行不同的重定向

我在我的应用程序中使用Ember简单身份验证并且它运行良好,但我遇到了一个我无法绕过的情况.

该库允许您通过覆盖指定成功验证后重定向到的路由routeAfterAuthentication: 'index'.这工作正常,但是,我发现自己处于一种我希望有两种不同类型的重定向的情况.当用户首次登录时,我希望他们去/dashboard,但是当他们第一次注册并进行身份验证时,我希望他们去/settings.

我希望在成功创建一个帐户后能够做这样的事情,但它仍然试图使用该routeAfterAuthentication选项进行转换:

var _this = this;

this.set('identification', _this.get('email'));
this.set('password', password);

this.send('authenticate', function() {
  _this.transitionToRoute('settings');
}, function() {});
Run Code Online (Sandbox Code Playgroud)

有没有办法在一次性验证后指定要转换到哪条路线?也许有更好的方法来记录某人创建帐户后无需通过该authenticate()方法?

ember.js ember-simple-auth

6
推荐指数
1
解决办法
3720
查看次数

使用简单身份验证从HTTP重定向到HTTPS

我希望得到一些关于如何使用带有ember-simple-auth的ember初始化程序将用户从HTTP重定向到HTTPS的建议.

`import ENV from 'cio/config/environment'`

SSLInitializer =
  name: 'ssl'
  before: 'simple-auth-cookie-store'
  initialize: (container, application) ->
    application.deferReadiness()

    # Redirect if hitting HTTP and SSL is enabled
    if ENV.SSL and window.location.protocol is "http:"
      window.location.href = "https:" + window.location.href.substring(window.location.protocol.length)
      return false

    application.advanceReadiness()

`export default SSLInitializer`
Run Code Online (Sandbox Code Playgroud)

但是,即使if语句的计算结果为true,cookie似乎也会失效.我尝试了几件事,包括:

  • 之前:'simple-auth'
  • 之前:'商店'
  • 在设置window.location.href之前,if语句中的application.destroy()

据我所知,经过调试.该应用程序确实重定向到HTTPS,但在document.cookie中找不到cookieName.(https://github.com/simplabs/ember-simple-auth/blob/master/packages/ember-simple-auth-cookie-store/lib/simple-auth-cookie-store/stores/cookie.js#L154)

在此方法有效之前,因为我们在index.html中有简单的代码段,但是我们希望将它保存在初始化程序中.有什么建议?

谢谢!

ember.js ember-simple-auth

6
推荐指数
1
解决办法
512
查看次数

如何将用户存储在会话中

我正在尝试使用django-rest-framework后端设置ember-simple-auth,但是我在将用户保存到会话时遇到了一些麻烦.我必须能够在我的模板中做这样的事情:

<h2>Welcome back, {{session.user}}</h2>
Run Code Online (Sandbox Code Playgroud)

因此,根据我发现的几个指南,我已经获得了身份验证和授权,因此我可以获得有效的令牌并在请求中使用.为了让用户参与会话,我进行了修改,App.CustomAuthenticator.authenticate以便在返回令牌时,用户名也会存储到会话中:

authenticate: function(credentials) {
    var _this = this;
    return new Ember.RSVP.Promise(function(resolve, reject) {
        Ember.$.ajax({
            url: _this.tokenEndpoint,
            type: 'POST',
            data: JSON.stringify({username: credentials.identification, password: credentials.password }),
            contentType: 'application/json'
        }).then(function(response) {
            Ember.run(function() {
                resolve({
                    token: response.token,
                    username: credentials.identification
                });
            });
        }, function(xhr, status, error) {
            var response = JSON.parse(xhr.responseText);
            Ember.run(function() {
                reject(response.error);
            });
        });
    });
},
Run Code Online (Sandbox Code Playgroud)

然后我修改Application.intializersession一个user属性:

Ember.Application.initializer({
    name: 'authentication',
    before: 'simple-auth',
    initialize: function(container, application) {
        // register the custom authenticator …
Run Code Online (Sandbox Code Playgroud)

ember.js django-rest-framework ember-simple-auth

5
推荐指数
2
解决办法
5102
查看次数

如何在ember cli中使用自定义授权器和自定义身份验证器来实现ember simple-auth

我不明白我应该如何将自定义身份验证器和自定义授权者包含在ember cli中.

在哪里放置它以及包含什么以及如何操作.简而言之,简单身份验证的cli示例不包括自定义授权程序和身份验证程序.

构建成功,但在浏览器中运行时,我收到错误

TypeError: SimpleAuth.Authenticators is undefined
Run Code Online (Sandbox Code Playgroud)

我知道我做错了什么,但是请你指导我或指出正确的文档如何做到这一点,我找不到任何东西:(我的初始化程序看起来像这样:

import Ember from 'ember';
import CustomAuthenticator from "../models/customauthenticator";

export default {
  name : 'authentication',
  before : 'simple-auth',
  initialize : function(container) {
    container.register('authenticator:custom', CustomAuthenticator);
    //container.register('authorizer:custom', CustomAuthorizer);
  }
};
Run Code Online (Sandbox Code Playgroud)

我的身份验证器看起来像这样

import Ember from "ember";
import App from '../app';
import SimpleAuth from "simple-auth/authenticators/base";

App.CustomAuthenticator = SimpleAuth.Authenticators.Base.extend({
  tokenEndpoint: '/api/RestUser.php/users/core/access/',

  restore: function(data) {
    [...]
  },
  authenticate: function(credentials) {
    [...]
  },
  invalidate: function() {
    [...]
  }
});
Run Code Online (Sandbox Code Playgroud)

我错过了什么?提前致谢!

ember.js ember-cli ember-simple-auth

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

ember-simple-auth不会为每个请求添加令牌

我正在使用Ember 1.8.1,Ember Data 1.0.0-beta.12,Handlebars 1.3.0,jQuery 1.11.1,Ember Simple Auth 0.7.2和Ember Simple Auth Devise 0.7.2作为我的前端.我的后端支持Rails,Grape和Devise.

现在我正在尝试构建一个简单的身份验证.登录效果很好:Ember应用程序将登录凭据发送到我的Rails API并获取访问令牌.令牌被写入localStorage并重新加载页面工作正常.但据我了解Ember Simple Auth(参见本演示),所有未来的AJAX请求都将使用此标记作为Authorization标题执行- 但事实并非如此.

我是否必须自己设置ajaxPrefilter或者Ember Simple Auth为我做这个并且我的代码/ Ember Simple Auth中有一些错误?

更新1

我刚刚玩了一些console.log调试.似乎该authorize函数不会被触发.除了之外,所有其他功能都可以成功记录authorize.

更新2

问题解决:忘了设置crossOriginWhitelist.

在此输入图像描述

devise ember.js ember-simple-auth

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

在 emberjs 中管理用户角色?

我有一个 nodejs api,如下所示

route.post("/token",function(req,res){
    authLib
        .checkForm(req.body)
        .then(authLib.findUser)
        .then(authLib.isValidUser)
        .then(authLib.authenticate)
        .then(authLib.genToken)
        .then((token)=>{
            res
                .status(200)
                .json({'access_token': token});
        })
        .catch((err)=>{
            res
                .status(400)
                .json({'error': err.message});
        });
});
Run Code Online (Sandbox Code Playgroud)

model用户包含用户角色的字段。每个用户角色都有不同的仪表板。我已经实现了 ember-simple-auth,oauth2-password-grant仪表板的模板如下所示

{{#if session.isAuthenticated}}
    {{#app-dashboard}}
    {{/app-dashboard}}
{{else}}
    {{#landing-app}}
    {{/landing-app}}
{{/if}}
Run Code Online (Sandbox Code Playgroud)

问题是我如何区分用户角色。一种方法可能是使用 ajax 请求来获取角色,但这意味着对所有视图都有一个额外的 XHR 请求。使用 XHR 的另一个问题Ember.$是授权令牌没有附加到请求中。解决此问题的最佳方法是什么?

node.js ember.js ember-simple-auth

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