Google Cloud Endpoints with another oAuth2 provider
Asked Answered
H

4

19

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)

Henequen answered 8/4, 2013 at 6:0 Comment(1)
Check this out: #18717174Lucialucian
F
5

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.

Fizgig answered 8/4, 2013 at 14:52 Comment(6)
Is there a way to implement an alternative? Like storing User in the session? (I just discovered that session also does not work in Google Cloud Endpoint)Henequen
Sure, you can implement any alternative you want, and you can pass your systems' tokens via endpoints, but you will have to implement the authentication yourself.Fizgig
the problem here is how to control the user session, because Google Endpoint not provide session, right?Henequen
Yes, that is my understanding.Fizgig
You can use endpoints with Sessions enabled. You just need to enable them in your appengine-web.xml using <sessions-enabled>true</sessions-enabled>Heraldry
@InsaurraldeAP it's not true. You can either implement your own auth schema or implement OAuth with some other provider.Conic
C
7

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.

Chatav answered 13/12, 2014 at 9:22 Comment(3)
Is there a python equivalent?Charil
@JanuszSkonieczny I've no idea whether or not it's available for python, you should probably ask a new question on SOChatav
anyone know how to put the data inside the header from android client?Byars
F
5

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.

Fizgig answered 8/4, 2013 at 14:52 Comment(6)
Is there a way to implement an alternative? Like storing User in the session? (I just discovered that session also does not work in Google Cloud Endpoint)Henequen
Sure, you can implement any alternative you want, and you can pass your systems' tokens via endpoints, but you will have to implement the authentication yourself.Fizgig
the problem here is how to control the user session, because Google Endpoint not provide session, right?Henequen
Yes, that is my understanding.Fizgig
You can use endpoints with Sessions enabled. You just need to enable them in your appengine-web.xml using <sessions-enabled>true</sessions-enabled>Heraldry
@InsaurraldeAP it's not true. You can either implement your own auth schema or implement OAuth with some other provider.Conic
C
2

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

Cantu answered 20/4, 2014 at 3:12 Comment(0)
S
2

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.

Susa answered 11/6, 2015 at 17:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.