Spring-security-oAuth2 Share

Spring-security-oAuth2 Share

oAuth2 Profile

OAuth 2.0 is the industry standard protocol for authorization. OAuth 2.0 is committed to simplifying the work of the client developers, while providing specific authorization process for Web applications, desktop applications, mobile phones, devices and living room. The specification and its extensions are IETF OAuth working group to develop within.


Code address

https://github.com/guo-yong123/spring-cloud-security-oauth2.git

oAuth2 mainly includes the following major role

  • Owner Resources
  • Clients include client_id and client_secret

  • The authentication server (Authorization server): That is a service provider dedicated server to handle authentication, simple point that is the login function (verify the user's account password is correct and assign the appropriate permissions)
  • Resource Server (Resource server): namely ISP server resources to store user-generated. It authentication server, which can be the same server, it can be a different server. Simply put, it is the entrance to access resources, such as the section mentioned in the "cloud note-taking service" and "cloud album service" can be called the resource server.
  • Interactive process

    oAuth2 four kinds of authorized types, the main mode of said authorization code and password mode

  • Authorization Code mode

    • Authorization code is a temporary certificate, in exchange for access_token and refresh_token

      code can only be used once, run out void.

    • 这个 code 的作用是保护 token 的安全性。如果直接把 token 返回给应用,很容易被拦截、窃听。引入了 code 之后,即使攻击者能够窃取到 code,但是由于他无法获得应用保存在服务器的 client_secret,因此也无法通过 code 换取 token。使用code换取token为什么不容易被拦截、窃听呢?这是因为,首先,这是一个从服务器到服务器的访问,黑客比较难捕捉到;其次,这个请求通常要求是 https 的实现。即使能窃听到数据包也无法解析出内容。

      有了这个 code,token 的安全性大大提高。因此,oAuth2.0 鼓励使用这种方式进行授权,而简单模式则是在不得已情况下才会使用。

    • 获取授权码
      http://localhost:9090/oauth/authorize?client_id=client&response_type=code 
    • 获取token  
      http://localhost:8080/oauth/token?grant_type=authorization_code&code=
  • 密码模式

    • 密码模式中,用户向客户端提供自己的用户名和密码。客户端使用这些信息,向 "服务商提供商" 索要授权。在这种模式中,用户必须把自己的密码给客户端,但是客户端不得储存密码。这通常用在用户对客户端高度信任的情况下,比如客户端是操作系统的一部分。

      一个典型的例子是同一个企业内部的不同产品要使用本企业的 oAuth2.0 体系。

      获取token
      http://localhost:9090/oauth/token?username=user&password=123456&grant_type=password&scope=select&client_id=client_2&client_secret=123456
  • oauth2提供的默认端点

    • /oauth/authorize:授权端点
      /oauth/token:令牌端点
      /oauth/confirm_access:用户确认授权提交端点
      /oauth/error:授权服务错误信息端点
      /oauth/check_token:用于资源服务访问的令牌解析端点
      /oauth/token_key:提供公有密匙的端点,如果使用JWT令牌的话

Guess you like

Origin www.cnblogs.com/quartz/p/11975483.html