In this tutorial, you will learn how to use Google’s OAuth 2.0 Authorization Server with Membrane API Gateway to authorize HTTP requests following RFC 6749 (OAuth 2.0) and OpenID Connect Core 1.0.
This tutorial covers:
You will need about 10 minutes, a Google account, an internet connection, and the Membrane API Gateway.
Step 1: Open Google Cloud Console
Go to https://console.cloud.google.com and sign in.
Step 2: Create a Project
Click the project selector on the top bar and select New Project. Enter a name such as My Secret Resource and click Create.
Step 3: Configure the OAuth Consent Screen
Open the navigation menu on the left and select Google Auth Platform then OAuth consent screen.
Step 4: Create an OAuth Client ID
http://localhost:8080/oauth2callback.http://localhost:8080.Keep this browser tab open because you will need these credentials later for Membrane.
Navigate to $MEMBRANE_HOME/examples/security/oauth2/google and open proxies.xml for
editing.
<router>
<api port="8080">
<oauth2Resource2>
<google
clientId="YOUR_CLIENT_ID"
clientSecret="YOUR_CLIENT_SECRET" />
</oauth2Resource2>
<groovy>
def email = exc.properties.'membrane.oauth2'.userinfo.email
exc.response = Response.ok("Hello " + email + ".").build()
RETURN
</groovy>
</api>
</router>
Listing 1: Sample OAuth2 configuration
Replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with the values from Google.
Step 5: Start Membrane
Run Membrane from that directory:
./membrane.sh
Membrane now listens on port 8080 for incoming HTTP connections.
Step 6: Access the “Secret Resource”
Open your browser and go to http://localhost:8080/. You will be redirected to Google’s login and consent screen.
Sign in, click Allow, and you will be redirected back to Membrane.
You should see a message such as Hello <your.email@example.com>.
Congratulations. You have successfully completed an OAuth2 setup with Google Auth Platform.
You have configured Google’s OAuth2 authorization server and Membrane as a client to authorize users using OpenID Connect. Membrane automatically uses Google’s discovery endpoints to retrieve all required OAuth2 URLs.