简体   繁体   English

使用OAuth2在Spring Security中进行用户授权

[英]User authorization in spring security using OAuth2

I'm currently investigating OAuth2 with spring-security and spring boot. 我目前正在调查具有弹簧安全性和弹簧启动的OAuth2。 Although the concept of this protocol is quite clear to me the implementation details are not (spring does not provide many examples and tutorials to work with). 尽管该协议的概念对我来说很清楚,但实现细节尚不清楚(spring没有提供许多示例和教程供您使用)。 Because of that I would be very grateful for answering my questions below: 因此,我非常感谢您回答以下问题:

  1. What is purpose of "password" grant type? “密码”授予类型的目的是什么? OAuth2 specs doesn't mention about it. OAuth2规范没有提及。 Is it just Spring implementation of some kind "authorization shortcut"? 仅仅是Spring某种“授权快捷方式”的实现?
  2. How does resource server handle access tokens (check if it is still valid, scope etc.)? 资源服务器如何处理访问令牌(检查它是否仍然有效,范围等)? Does I need to implement something or it is provided by Spring Security and ResourceServerConfig? 我是否需要实现某些东西,或者它是Spring Security和ResourceServerConfig提供的?
  3. How RS will know which user (not client) has requested resources? RS如何知道哪个用户(而非客户端)已请求资源? Specific user resources are bound with ids, unique usernames and so on, does token have this kind of information? 特定的用户资源与ID,唯一的用户名等绑定,令牌是否具有此类信息? How to I retrieve it in order to use in resources controllers? 我如何检索它以便在资源控制器中使用?
  4. Authorization server (correct me if I'm wrong) is able to check if Client application has permission to requested resources or not. 授权服务器(如果我错了,请更正我)可以检查客户端应用程序是否有权访问所请求的资源。 As I understand it shouldn't be aware of Users (Resources Owners). 据我了解,它不应该知道用户(资源所有者)。 In situation where I authenticate via Google, Facebook or some other service user authentication is their case. 在我通过Google,Facebook或其他服务进行身份验证的情况下,用户身份验证就是这种情况。 What about application where OAuth2 and Resources Server are one application (I'm currently developing such one for test purposes), where I should put UserDetailsService? OAuth2和Resources Server是一个应用程序(我目前正在为测试目的而开发这种应用程序)的应用程序又该放置UserDetailsS​​ervice呢? And how combine it in order to authorize client (js generated from app in this case) at first, then user (Resource owner) and generate token? 以及如何组合它以便首先授权客户端(在这种情况下是从应用程序生成的js),然后再授权用户(资源所有者)并生成令牌? Currenly I have implemented ClientDetailService and injected to configuration. 目前,我已经实现了ClientDetailService并注入了配置。 Where should I inject UserDetailService? 我应该在哪里注入UserDetailService?

     @Configuration @EnableAuthorizationServer public class OAuth2Config extends AuthorizationServerConfigurerAdapter { @Autowired private AuthenticationManager authenticationManager; @Autowired private MongoClientDetailsService cds; @Override public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { endpoints.authenticationManager(authenticationManager); } @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients.withClientDetails(cds); } } 
  5. Are there some JS libraries that helps with authorization flow for custom applications like hello.js which supports (as far I as know) well known services? 是否有一些JS库有助于自定义应用程序(如hello.js)的授权流程,该程序支持(据我所知)众所周知的服务?

Any help would be appreciated:) 任何帮助,将不胜感激:)

That's a lot of questions; 有很多问题; let me start by answering 3: 让我首先回答3:

  1. the grant_type with the value password is the official reserved value for the Resource Owner Password Credentials grant type as shown in the spec here: https://tools.ietf.org/html/rfc6749#section-4.3.2 so it is not Spring specific or custom 带有password值的grant_type是“资源所有者密码凭据”授予类型的官方保留值,如此处的规范所示: https : grant_type ,因此它不是Spring具体或自定义

  2. the RS can validate the token itself if it is self-contained and structured (eg a JWT) or else it will need to make a callback to the Authorization Server to validate it 如果令牌是自包含的和结构化的(例如,JWT),则RS可以验证令牌本身,否则它将需要回调到授权服务器以对其进行验证

  3. the validation result from step 2. may include information about the user (or: Resource Owner) who granted access to the client 步骤2的验证结果。其中可能包含有关授予客户端访问权限的用户(或:资源所有者)的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM