简体   繁体   English

RESTful服务上的自定义手动Oauth2身份验证

[英]Custom Manual Oauth2 Authentication at RESTful Service

I am developing some RESTful services for our mobile app using Spring Boot. 我正在使用Spring Boot为我们的移动应用程序开发一些RESTful服务。 I succesfully implemented Oauth2 authentication with our registration using username and password. 我使用用户名和密码成功注册了Oauth2身份验证。 Users can authenticate by using username and password. 用户可以使用用户名和密码进行身份验证。 Also our client want to be authenticated with their custom token. 另外,我们的客户希望使用其自定义令牌进行身份验证。 They have a web service that you send token and response is true or false. 他们有一个Web服务,您可以发送令牌,并且响应是对还是错。

My first thought was, I can write a service like /custom-login and that service accepts custom token. 我的第一个想法是,我可以编写类似/ custom-login的服务,并且该服务接受自定义令牌。 In my service I can check this token with external service and if it is valid I call oauth2 authentication and return oauth2 authentication response. 在我的服务中,我可以与外部服务一起检查此令牌,如果它有效,则调用oauth2身份验证并返回oauth2身份验证响应。

How can I implement custom authentication oauth2 ? 如何实现自定义身份验证oauth2?

OAuth2.0 spec allows for custom grant types, OAuth2.0规范允许自定义授权类型,

So your auth server can create an custom grant type, 因此,您的身份验证服务器可以创建自定义授予类型,

for eg: let's assume your wanted to authenticate with Google using Google access token, so you will create new grant_type called google_token 例如:假设您要使用Google访问令牌向Google进行身份验证,因此您将创建名为google_token的Grant_type

So now when your users wanted to authenticate using Google access token , they will pass like 因此,现在当您的用户想要使用Google访问令牌进行身份验证时,他们将像

grant_type=google_token&client_id=clientId&client_secret=secret&google_token=google-access-token

Then your auth server can verify the access token with Google and optionally verify client is issued to, etc and once verified , it can return your own access token 然后,您的身份验证服务器可以通过Google验证访问令牌,还可以选择验证是否向客户端颁发了访问令牌,等等,一旦完成验证,它就可以返回您自己的访问令牌

This applies for third party auth severs, so you can create number of custom grant types 这适用于第三方身份验证服务器,因此您可以创建许多自定义授权类型

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

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