Ember Simple Auth Token 使用教程

Ember Simple Auth Token 使用教程

ember-simple-auth-tokenEmber Simple Auth extension that is compatible with token-based authentication like JWT.项目地址:https://gitcode.com/gh_mirrors/em/ember-simple-auth-token

1. 项目的目录结构及介绍

Ember Simple Auth Token 项目的目录结构遵循标准的 Ember CLI 项目结构。以下是主要目录和文件的介绍:

ember-simple-auth-token/
├── app/
│   ├── adapters/
│   ├── components/
│   ├── controllers/
│   ├── models/
│   ├── routes/
│   ├── serializers/
│   ├── services/
│   ├── templates/
│   └── router.js
├── config/
│   └── environment.js
├── ember-cli-build.js
├── package.json
├── public/
├── tests/
└── vendor/
  • app/: 包含应用程序的源代码,包括路由、控制器、模型、组件等。
  • config/: 包含应用程序的配置文件,如 environment.js
  • ember-cli-build.js: Ember CLI 构建配置文件。
  • package.json: 项目的依赖和脚本。
  • public/: 静态资源文件夹。
  • tests/: 测试文件夹。
  • vendor/: 第三方库文件夹。

2. 项目的启动文件介绍

Ember Simple Auth Token 项目的启动文件主要是 app/app.jsconfig/environment.js

app/app.js

这是 Ember 应用程序的入口文件,负责初始化应用程序实例:

import Application from '@ember/application';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

const App = Application.extend({
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix,
  Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;

config/environment.js

这是 Ember 应用程序的配置文件,包含不同环境的配置信息:

'use strict';

module.exports = function(environment) {
  let ENV = {
    modulePrefix: 'your-app-name',
    environment,
    rootURL: '/',
    locationType: 'auto',
    EmberENV: {
      FEATURES: {
        // 在这里添加 Ember 特性
      },
      EXTEND_PROTOTYPES: {
        // 禁用日期原型扩展
        Date: false
      }
    },

    APP: {
      // 在这里添加应用程序的配置
    }
  };

  if (environment === 'development') {
    // 开发环境配置
  }

  if (environment === 'test') {
    // 测试环境配置
  }

  if (environment === 'production') {
    // 生产环境配置
  }

  return ENV;
};

3. 项目的配置文件介绍

Ember Simple Auth Token 的配置主要在 config/environment.js 文件中进行。以下是一些关键配置项:

Token Authenticator 配置

ENV['ember-simple-auth-token'] = {
  serverTokenEndpoint: '/api/token-auth/', // 服务器认证端点
  tokenPropertyName: 'token', // 服务器响应中的 token 键名
  headers: {} // 认证请求中添加的头部信息
};

JSON Web Token Authenticator 配置

ENV['ember-simple-auth-token'] = {
  serverTokenEndpoint: '/api/token-auth/',
  tokenPropertyName: 'token',
  headers: {},
  refreshAccessTokens: false, // 是否自动刷新 token
  tokenExpirationInvalidateSession: false // token 过期是否使会话失效
};

这些配置项可以根据具体需求进行调整,以适应不同的认证需求。

ember-simple-auth-tokenEmber Simple Auth extension that is compatible with token-based authentication like JWT.项目地址:https://gitcode.com/gh_mirrors/em/ember-simple-auth-token

  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

樊贝路Strawberry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值