visit
The idea of an authorization open standard started with OAuth around 2006. Because of a security issue, OAuth 2.0 superseded the initial version. OAuth 2.0 became an IETF RFC in 2012:
The OAuth 2.0 authorization framework enables a third-party application to obtain limited access to an HTTP service, either on behalf of a resource owner by orchestrating an approval interaction between the resource owner and the HTTP service, or by allowing the
third-party application to obtain access on its own behalf.
—
OAuth focuses mostly on authorization; the authentication part is pretty light: it contains a section about Client Password authentication and one Other Authentication Methods.
The authorization server MAY support any suitable HTTP authentication scheme matching its security requirements. When using other authentication methods, the authorization server MUST define a mapping between the client identifier (registration record) and authentication scheme.
—
OpenID Connect uses OAuth 2.0 and adds the authentication part:
OpenID Connect 1.0 is a simple identity layer on top of the OAuth 2.0 protocol. It allows Clients to verify the identity of the End-User based on the authentication performed by an Authorization Server, as well as to obtain basic profile information about the End-User in an interoperable and REST-like manner.
OpenID Connect allows clients of all types, including Web-based, mobile, and JavaScript clients, to request and receive information about authenticated sessions and end-users. The specification suite is extensible, allowing participants to use optional features such as encryption of identity data, discovery of OpenID Providers, and logout, when it makes sense for them.
—
version: "3"
services:
apisix:
image: apache/apisix:3.1.0-debian #1
ports:
- "9080:9080"
volumes:
- ./apisix/config.yml:/usr/local/apisix/conf/config.yaml:ro #2
- ./apisix/apisix.yml:/usr/local/apisix/conf/apisix.yaml:ro #3
env_file:
- .env
httpbin:
image: kennethreitz/httpbin #4
routes:
- uri: /* #1
upstream:
nodes:
"httpbin:80": 1 #1
plugins:
openid-connect:
client_id: ${{OIDC_CLIENTID}} #2
client_secret: ${{OIDC_SECRET}} #2
discovery: //${{OIDC_ISSUER}}/.well-known/openid-configuration #2#3
redirect_uri: //localhost:9080/callback #4
scope: openid #5
session:
secret: ${{SESSION_SECRET}} #6
#END
In the project context, navigate APIs & Services | Credentials.
Then, press the + CREATE CREDENTIALS button in the upper menu bar.
Select OAuth Client Id in the scrolling menu.
Fill in the fields:
<URL>/callback
, e.g., //localhost:9080/callback
URL
should be the URL of the web application. Likewise, /callback
should match the openid-connect
plugin configuration above.
Note that Google doesn't allow relative URLs, so if you need to reuse the application in different environments, you need to add the URL of each environment. Click the Create button.
In the Docker Compose configuration above, use the Client ID and Client Secret as OIDC_CLIENTID
and OIDC_SECRET
. I wrote them down as environment variables in a .env
file.
The last missing variable is OIDC_ISSUER
: it's accounts.google.com
. If you navigate to , you'll see all data required by OAuth 2.0 (and more).
At this point, we can start our setup with docker compose up
. When we navigate to , the browser redirects us to the Google authentication page.
OIDC_CLIENTID
OIDC_SECRET
OIDC_ISSUER
: on Azure, it should look something like login.microsoftonline.com/<TENANT_ID>/v2.0
To go further:
Originally published at on March 5th, 2023