Internal SSO (OpenID Connect Provider)

OpenID Connect

What is OpenID Connect?

OpenID Connect is an identity layer built on top of OAuth2, it allows third-party applications to get basic information about your profile and verify your identity. Its purpose is to give you one login for multiple sites. You're probably familiar with it if you used Login with Google. For example, if you click Login with Google you'll be redirected to the Google page with verify form that you allow some website to get information from your profile for example email, name, etc.

Defguard as an OpenID Connect Provider

Defguard is a full-featured OIDC provider enabling SSO (Single Sign-On) across third-party applications. Apps can authenticate users through Defguard identity system using standard OIDC flow.

Example:

How Defguard implements OpenID?

As an identity provider, Defguard enables you to sign in to third-party services using your Defguard account, so you don't have to worry about managing multiple passwords.

At this point, you may wonder whether this is safe? And yes, it is completely safe. Third-party applications only receive the data based on the scopes you approve during consent screen.

This information is then sent to the third party application as an ID Token which is a JSON Web Token containing additional claims such as first name or email. Your password is never sent at any stage of this process.

Defguard OpenID flow

OpenID flow

How to enable login with Defguard using OpenID?

Client creation

To enable logging in with third-party application first you need to register it as new OpenID client.

To do it, navigate to OpenID applications on the left side navigation, then click Add new application.

After clicking "Add new application" button, you will see "Add new OpenID application" modal

circle-info

Application name - Your application name

Redirect URL - URL to which user will be redirected with generated PKCE code example (https://myapp.com/redirect_uri). You can specify multiple redirect URL, to add another click "Add URL".

Scopes - select scopes which your client will be using

After creating new OpenID application you will see it inside the "All applications".

Client credentials

Applications must be registered with the authorization server to enable secure authentication and identification. To do it, you need to obtain credentials described below.

Client ID - Public identifier assigned to application during registration. It is used to identify the client in authentication request and doesn't need to be secret.

Client Secret - A confidential credential only known to the authorization server and client application. It is used to authenticate the application during communication.

To obtain Client ID/Client Secret, click three dots on the right side of the row containing your OpenID application.

After clicking Copy client ID/Copy client secret, credential will be saved to your clipboard.

OpenID endpoints

Discovery endpoint

OpenID Connect defines a discovery mechanism, called OpenID Connect Discovery, where an OpenID server publishes its metadata at a well-known URL, typically. This URL returns a JSON listing of the OpenID/OAuth endpoints, supported scopes and claims, public keys used to sign the tokens, and other details. The clients can use this information to construct a request to the OpenID server.

https://defguard.company.net/.well-known/openid-configuration

Authorization

Token

UserInfo

Authentication request

Set up your login with Defguard button to redirect to authorization endpoint, which is https://defguard.company.net/openid/authorize?

Below is a sample authentication request which your app should do on Login with Defguard button

Notes:

  1. Client ID and Client Secret are generated by Defguard after creating your app.

  2. Scope must include OpenID

  3. Available scopes are Profile (all available info from user profile) Phone and Email

  4. Currently, only supported response_type is code.

  5. Redirect URI is URL to which the user will be redirected with and authorization code. It must exactly match the redirect URL registered during client creation, otherwise error will be returned.

Successful authentication response

Exchange code for ID Token

After receiving code from previous step, you need to exchange it for token on token endpoint:

Request Header and URL:

Request body: Need to be form encoded

circle-info
  • Currently, only supported grant_type is authorization_code

  • Code is your PKCE code received in previous step

Successful Token Response

circle-info

ID Tokens are signed using RS256 (RSA Signature with SHA-256).

The public key is available via endpoint /api/v1/oauth/discovery/keys

Authorized apps

Every user that used Login with Defguard option can see (on own profile) name of every authorized app. If you revoke app, then you will have to click allow on the form with permissions again.

OpenID clients

Below, you can find tutorials on how to configure OpenID for:

Portainerchevron-rightGrafana setupchevron-rightProxmoxchevron-rightDjangochevron-rightMatrix / Synapsechevron-rightMinIOchevron-rightVaultchevron-right

Last updated

Was this helpful?