Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Endpoints with another oAuth2 provider

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)

like image 776
Douglas Correa Avatar asked Apr 08 '13 06:04

Douglas Correa


People also ask

What is Google OAuth redirect URI?

The redirect URIs are the endpoints to which the OAuth 2.0 server can send responses. These endpoints must adhere to Google's validation rules. For testing, you can specify URIs that refer to the local machine, such as http://localhost:8080 .

What are the different methods for authentication of Google Compute Engine API?

With a user account, you can authenticate to Google APIs and services in the following ways: Use the gcloud CLI to set up Application Default Credentials (ADC). Use the gcloud CLI to generate access tokens. Use your user credentials to impersonate a service account.


2 Answers

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.

like image 66
tomrozb Avatar answered Oct 30 '22 20:10

tomrozb


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.

like image 23
Tom Avatar answered Oct 30 '22 21:10

Tom