开源项目 `authorization-lambda-at-edge` 使用教程

开源项目 authorization-lambda-at-edge 使用教程

authorization-lambda-at-edgeCode demonstrates authorization with Lambda@Edge and JSON Web Tokens (JWTs)项目地址:https://gitcode.com/gh_mirrors/au/authorization-lambda-at-edge

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

authorization-lambda-at-edge/
├── README.md
├── cloudformation
│   └── template.yaml
├── lambda
│   ├── authorizer
│   │   ├── index.js
│   │   └── package.json
│   └── viewer-request
│       ├── index.js
│       └── package.json
└── scripts
    └── deploy.sh
  • README.md: 项目说明文档。
  • cloudformation/template.yaml: CloudFormation 模板文件,用于部署 AWS 资源。
  • lambda/authorizer/index.js: Lambda 函数代码,用于授权处理。
  • lambda/authorizer/package.json: Lambda 函数依赖包配置文件。
  • lambda/viewer-request/index.js: Lambda 函数代码,用于处理 viewer request。
  • lambda/viewer-request/package.json: Lambda 函数依赖包配置文件。
  • scripts/deploy.sh: 部署脚本。

2. 项目的启动文件介绍

lambda/authorizer/index.js

该文件是 Lambda 函数的入口文件,主要负责处理授权逻辑。代码示例如下:

exports.handler = async (event) => {
    // 授权逻辑处理
};

lambda/viewer-request/index.js

该文件是 Lambda 函数的入口文件,主要负责处理 viewer request。代码示例如下:

exports.handler = async (event) => {
    // viewer request 处理逻辑
};

3. 项目的配置文件介绍

cloudformation/template.yaml

该文件是 CloudFormation 模板文件,用于定义 AWS 资源的配置。示例如下:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  LambdaFunction:
    Type: 'AWS::Lambda::Function'
    Properties:
      Handler: 'index.handler'
      Role: !GetAtt LambdaExecutionRole.Arn
      Code:
        S3Bucket: 'my-bucket'
        S3Key: 'my-key'
      Runtime: 'nodejs14.x'

lambda/authorizer/package.json

该文件是 Lambda 函数的依赖包配置文件,定义了所需的 npm 包。示例如下:

{
  "name": "authorizer",
  "version": "1.0.0",
  "dependencies": {
    "jsonwebtoken": "^8.5.1"
  }
}

lambda/viewer-request/package.json

该文件是 Lambda 函数的依赖包配置文件,定义了所需的 npm 包。示例如下:

{
  "name": "viewer-request",
  "version": "1.0.0",
  "dependencies": {
    "aws-sdk": "^2.814.0"
  }
}

以上是 authorization-lambda-at-edge 项目的目录结构、启动文件和配置文件的介绍。希望这份教程能帮助你更好地理解和使用该项目。

authorization-lambda-at-edgeCode demonstrates authorization with Lambda@Edge and JSON Web Tokens (JWTs)项目地址:https://gitcode.com/gh_mirrors/au/authorization-lambda-at-edge

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Spring Authorization Server 是一个基于 Spring Security 的授权服务器开发框架,可以快速构建 OAuth2 授权服务器和 OpenID Connect 提供方。 下面是接入 Spring Authorization Server 的简单教程: 1. 添加依赖 在 `pom.xml` 文件中添加以下依赖: ```xml <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-oauth2-authorization-server</artifactId> <version>0.2.1</version> </dependency> ``` 2. 配置授权服务器 在 `application.yml` 或 `application.properties` 文件中添加以下配置: ```yaml spring: security: oauth2: authorization: server: jwt: signing: key-value: ${JWT_KEY_VALUE} # JWT 密钥 clients: registration: test-client: # 客户端 ID client-id: ${CLIENT_ID} # 客户端 ID client-secret: ${CLIENT_SECRET} # 客户端密钥 redirect-uri: http://localhost:8080/login/oauth2/code/test-client # 授权回调地址 authorization-grant-type: authorization_code # 授权类型 scopes: - read # 授权范围 - write ``` 3. 配置 Spring Security 在 Spring Security 配置类中添加以下配置: ```java @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests(authorizeRequests -> authorizeRequests .antMatchers("/oauth2/**").permitAll() .anyRequest().authenticated() ) .oauth2Login(); } } ``` 4. 启动应用程序 现在,您可以启动应用程序并在浏览器中访问 `http://localhost:8080/oauth2/authorize?client_id=test-client&response_type=code&scope=read`,以获取授权码并进行授权。 以上就是简单的 Spring Authorization Server 接入教程,希望对你有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

崔锴业Wolf

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

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

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

打赏作者

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

抵扣说明:

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

余额充值