Spring Cloud Gateway主要用于以下角色之一:

  • OAuth Client
  • OAuth Resource Server

1  Spring Cloud Gateway as an OAuth 2.0 Client

在这种情况下,任何未经身份验证的传入请求都将启动授权码流程。网关获取令牌后,将在向后端服务发送请求时使用它:

添加依赖

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>

application.yml


server:
port: 8080
servlet:
context-path: /api
spring:
security:
oauth2:
client:
registration:
cjscustom:
client-id: client-1
client-secret: 123456789
client-authentication-method: client_secret_basic
authorization-grant-type: authorization_code
redirect-uri: http://127.0.0.1:8080/api/login/oauth2/code/cjscustom
scope: openid,profile
provider:
cjscustom:
authorization-uri: http://localhost:9000/oauth2/authorize
token-uri: http://localhost:9000/oauth2/token
jwk-set-uri: http://localhost:9000/oauth2/jwks
cloud:
gateway:
default-filters:
- TokenRelay=
routes:
- id: resource-server-1
uri: http://localhost:8082
predicates:
- Path=/resource-1/**
- id: resource-server-2
uri: http://localhost:8083
predicates:
- Path=/resource-2/**
logging:
level:
root: debug

2  Spring Cloud Gateway as an OAuth 2.0 Resource Server

在这里,Gateway充当了网关守卫的角色,强制每个请求在发送到后端服务之前都有一个有效的访问令牌。此外,它还可以根据关联的作用域检查令牌是否具有访问给定资源的适当权限:

3  参考

https://www.baeldung.com/spring-cloud-gateway-oauth2

https://docs.spring.io/spring-cloud-gateway/docs/current/reference/html/#token-relay-gatewayfilter-factory

https://datatracker.ietf.org/doc/html/rfc6749

https://www.rfc-editor.org/rfc/rfc6749

在OAuth 2.0模式下使用Spring Cloud Gateway的更多相关文章

  1. 阿里Sentinel支持Spring Cloud Gateway啦

    1. 前言 4月25号,Sentinel 1.6.0 正式发布,带来 Spring Cloud Gateway 支持.控制台登录功能.改进的热点限流和注解 fallback 等多项新特性,该出手时就出 ...

  2. Spring Cloud Gateway(八):其它路由谓词工厂

    本文基于 spring cloud gateway 2.0.1 6.基于Cookie的谓词工厂 CookieRoutePredicateFactory 是 Cookie 类型的路由断言工厂,接收两个参 ...

  3. Spring Cloud Gateway+Nacos,yml+properties两种配置文件方式搭建网关服务

    写在前面 网关的作用不在此赘述,举个最常用的例子,我们搭建了微服务,前端调用各服务接口时,由于各服务接口不一样,如果让前端同事分别调用,前端同事会疯的.而网关就可以解决这个问题,网关屏蔽了各业务服务的 ...

  4. 快速突击 Spring Cloud Gateway

    认识 Spring Cloud Gateway Spring Cloud Gateway 是一款基于 Spring 5,Project Reactor 以及 Spring Boot 2 构建的 API ...

  5. 妹子始终没搞懂OAuth2.0,今天整合Spring Cloud Security 一次说明白!

    大家好,我是不才陈某~ 周二发了Spring Security 系列第一篇文章,有妹子留言说看了很多文章,始终没明白OAuth2.0,这次陈某花了两天时间,整理了OAuth2.0相关的知识,结合认证授 ...

  6. Spring Cloud实战 | 最终篇:Spring Cloud Gateway+Spring Security OAuth2集成统一认证授权平台下实现注销使JWT失效方案

    一. 前言 在上一篇文章介绍 youlai-mall 项目中,通过整合Spring Cloud Gateway.Spring Security OAuth2.JWT等技术实现了微服务下统一认证授权平台 ...

  7. 从0开始构建你的api网关--Spring Cloud Gateway网关实战及原理解析

    API 网关 API 网关出现的原因是微服务架构的出现,不同的微服务一般会有不同的网络地址,而外部客户端可能需要调用多个服务的接口才能完成一个业务需求,如果让客户端直接与各个微服务通信,会有以下的问题 ...

  8. Docker下的Spring Cloud三部曲之一:极速体验

    版权声明:欢迎转载,请注明出处,谢谢. http://blog.csdn.net/boling_cavalry/article/details/79177930   目录(?)[+]   从本章开始, ...

  9. 0.9.0.RELEASE版本的spring cloud alibaba sentinel+gateway网关实例

    sentinel除了让服务提供方.消费方用之外,网关也能用它来限流.我们基于上次整的网关(参见0.9.0.RELEASE版本的spring cloud alibaba nacos+gateway网关实 ...

  10. 0.9.0.RELEASE版本的spring cloud alibaba nacos+gateway网关实例

    gateway就是用来替换zuul的,功能都差不多,我们看下它怎么来跟nacos一起玩.老套路,三板斧: 1.pom: <?xml version="1.0" encodin ...

随机推荐

  1. [转帖]DOCKER默认网段和主机网段冲突解决

    https://www.cnblogs.com/yinliang/p/13189334.html 一. docker默认网卡docker0 172.17.0.0可能会与主机冲突,这时候需要修改dock ...

  2. [转帖]CygWin、MingW、MSYS之间的关系

    https://www.jianshu.com/p/09198f6e0a3c 前言 在跨平台开发或移植中,经常会听说Cygwin.MingW.MSYS,他们之间是什么关系?对于将要完成的任务,应该选择 ...

  3. [转帖]Datadog 能成为最大的云监控厂商吗

    https://xie.infoq.cn/article/901cfd6b284e3e103ac70aeb3 作者:睿象云 2021-03-25 本文字数:2256 字 阅读完需:约 7 分钟   D ...

  4. 【转帖】Linux性能优化(十三)——CPU性能测试

    一.CPU上下文切换测试场景 使用sysbench模拟多线程调度: sysbench --threads=10 --time=300 threads run 使用vmstat查看CPU上下文切换: c ...

  5. [转帖]解析Linux gcore: 揭示程序内存捕获的秘密(linuxgcore)

    https://www.dbs724.com/133618.html Linux gcore 是一种在Linux系统中使用命令行工具捕获进程内存内容的方法.它允许程序员制定程序的一个内存快照,从而帮助 ...

  6. [转帖]【JVM】JDK命令行工具

    在JDK/bin目录下我发现了许多命令行工具 这些命令有哪些作用呢,接下来我就来详细介绍一下 常用JDK命令行工具 命令名称 全称 用途 jstat JVM Statistics Monitoring ...

  7. [转帖]15 个必须知道的 chrome 开发工具技巧

    在Web开发者中,Google Chrome是使用最广泛的浏览器.六周一次的发布周期和一套强大的不断扩大开发功能,使其成为了web开发者必备的工具.你可能已经熟悉了它的部分功能,如使用console和 ...

  8. [转帖]kubelet 原理解析四:probeManager

    https://segmentfault.com/a/1190000022163835 概述 在Kubernetes 中,系统和应用程序的健康检查任务是由 kubelet 来完成的,本文主要讨论kub ...

  9. ARM 平台Docker运行RabbitMQ 以及迁移的简单办法

    公司网络很垃圾. 可以使用vps 进行下载和打包  放到 公司的机器上面进行使用. 1. 搜索有没有可用的镜像. [root@JNXLH ~]# docker search rabbitmq |gre ...

  10. CoreDNS的配置文件修改

    CoreDNS的配置文件修改 今天浪费了4个小时来调整coredns 这里简单记录一下 注意修改点: 1 kubernetes cluster.local. 需要增加集群内的配置 2 forward ...