Google Cloud Endpoints with another oAuth2 provider

◇◆丶佛笑我妖孽 提交于 2020-01-09 09:00:26

问题


Is there a way to use another OAuth2 provider with Google Cloud Endpoints? I mean for example, get authentication from Facebook and use it the same way we use Google Account Auth (using gapi js and putting User class on @ApiMethod)


回答1:


No. I came across someone else asking this question and the answer from the google folks (if I remember correctly) was that the endpoints user authentication currently only supports Google accounts.




回答2:


You have to implement your own Authenticator and update @Api configuration. Based on this answer a simple authenticator will look like this:

public class MyAuthenticator implements Authenticator {

    @Override
    public User authenticate(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        if (token != null) {
            // apply your Facebook/Twitter/OAuth2 authentication
            String user = authenticate(token);
            if (user != null) {
                return new User(user);
            }
        }
        return null;
    }
}

And your API definition

@Api(name = "example", authenticators = {MyAuthenticator.class})

More about custom authenticators you can find in Google documentation.




回答3:


I wrote an example exchanging a Facebook access token for one generated by my application, and validating it from within an endpoints method:

https://github.com/loudnate/appengine-endpoints-auth-example




回答4:


Google Cloud Endpoints allow you to recover User, HttpServletRequest and HttpServletContext into you API methods by injecting it as parameters.

It is not OAuth2 but here is a begining of a solution: https://www.yanchware.com/custom-authentication-for-google-cloud-endpoints/

The proposed solution is to inject HttpServletRequest in specific api methods to access the session.



来源:https://stackoverflow.com/questions/15872240/google-cloud-endpoints-with-another-oauth2-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!