【问题标题】:How to access Ember-Simple-Auth-Token authorizer header in NodeJS endpoint如何访问 NodeJS 端点中的 Ember-Simple-Auth-Token 授权标头
【发布时间】:2016-06-17 12:02:39
【问题描述】:

我试图找出授权者:应用程序在请求中的设置位置。它应该在标题中的某个地方吗?从应用程序发出请求时,我无法在 nodejs 端点的请求中找到它。

我在 ember (adapter/application.js) 中的代码是:

import DS from "ember-data";
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';

export default DS.RESTAdapter.extend(DataAdapterMixin, {
  authorizer: 'authorizer:application',

而且端点很简单:

exports.getAuthorizer = function(req, res) {
  console.log(req);
}

我已经记录了req,希望能在里面找到授权人,但找不到。

如果您需要更多信息,请告诉我,谢谢

ember-simple-auth-token:https://github.com/jpadilla/ember-simple-auth-token

【问题讨论】:

    标签: json node.js session ember.js ember-simple-auth


    【解决方案1】:

    要访问 API 中的授权令牌,我只需要简单地执行以下操作:

    exports.getAuthorizer = function(req, res) {
      if (req.headers.authorization && req.headers.authorization.split(' ')[0] === 'Bearer') {
        return req.headers.authorization.split(' ')[1];
      } else if (req.query && req.query.token) {
        return req.query.token;
      } else {
        return null;
      }
    }
    

    https://github.com/auth0/express-jwt

    首先阻止我这样做的是标头从未被发送。我有 ember-cli-simple-auth 和 ember-simple-auth。

    修复是从项目中删除 ember-cli-simple-auth 和 ember-cli-simple-auth-token (https://github.com/jpadilla/ember-simple-auth-token/issues/96)

    【讨论】:

      猜你喜欢
      • 2015-11-05
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      • 2020-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-06
      相关资源
      最近更新 更多