首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ember simple-auth和torii自定义认证器进行身份验证

使用ember simple-auth和torii自定义认证器进行身份验证
EN

Stack Overflow用户
提问于 2016-02-12 01:05:34
回答 1查看 162关注 0票数 0

我从session.isAuthenticated中得到了不同的行为,取决于我如何访问它。这可能只是我真正问题的一个症状。

发生了什么:

  1. 单击“登录”按钮
  2. 窗口弹出,提示登录。
  3. 登录,弹出就消失了
  4. 依赖于session.isAuthenticated的模板不会更改显示状态(即继续操作,好像它是假的或未定义的)。
  5. 如果我是console.log this.get('session.isAuthenticated'),我会得到true

当这只是托里,一切都在工作,所以我已经搞砸了,当添加烬-简单-不知道什么原因。

我收到了几个"DEPRECATION: Using the injected 'container' is deprecated. Please use the 'getOwner' helper instead to access the owner of this object警告,但当只有torii时,这些警告还能正常工作,所以我认为它们仍然没有问题。

templates/application.hbs

代码语言:javascript
复制
<header>
  <nav class="nav-main">
    {{#if session.isAuthenticated}}
      <button {{action 'invalidateSession'}}>Sign out</button>
    {{else}}
      <button {{action 'authenticate'}}>Sign in</button>
    {{/if}}

    Auth: {{session.isAuthenticated}}<br>
    <button {{action 'icanhaz'}}>test?</button>
  </nav>
</header>

routes/application.js

代码语言:javascript
复制
import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin, {
  session: Ember.inject.service('session'),
  actions: {
    authenticate() {
      this.get('session').authenticate('authenticator:torii', 'myprovider');
    },
    invalidateSession() {
      this.get('session').invalidate();
    },
    icanhaz() {
      console.log(this.get('session.isAuthenticated'));
    }
  }
});

adapters/application.js

代码语言:javascript
复制
import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
  host: 'https://myprovider.herokuapp.com',
  namespace: 'api/v2'
});

authenticators/torii.js

代码语言:javascript
复制
import Ember from 'ember';
import ToriiAuthenticator from 'ember-simple-auth/authenticators/torii';

export default ToriiAuthenticator.extend({
  torii: Ember.inject.service(),
})

environment.js

代码语言:javascript
复制
module.exports = function(environment) {
  var ENV = {
    modulePrefix: 'my-app-prefix',
    environment: environment,
    baseURL: '/',
    locationType: 'auto',
    },
    contentSecurityPolicy: {
        'connect-src': "'self' myprovider.herokuapp.com",
    },
    torii: {
      providers: {
        'myprovider': {
          apiKey: '6T7hlTUqfYMgcxkXPAOeNzVmC5L26bTYe9A8D5fc',
          scope: 'read write',
          redirectUri: 'http://localhost:4200'
        }
      }
    }
  };
};
EN

回答 1

Stack Overflow用户

发布于 2016-02-12 11:15:11

您必须将会话服务注入支持要在其中使用的模板的所有控制器/组件中。在使用application模板中的会话时,必须在application控制器中注入会话服务。将其注入application 路由并不能使其在模板中可用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35353067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档