OAuth Providers
Wisej.NET 4.2.0+
OAuthClient knows five providers, selected with its Provider property. Four are presets whose endpoints, scopes and quirks are built in; the fifth, OAuth2, is any standards-compliant OAuth 2.0 or OpenID Connect server you describe yourself. This page lists what to register with each provider and how to configure the component for it. For the flow itself, the events and the token handling, see OAuthClient.
For a complete list of properties, methods, and events, see the API documentation, and the OAuthProvider enumeration.
Comparison
| GitHub | Microsoft Entra ID | GitLab | OAuth2 (custom) | ||
|---|---|---|---|---|---|
| Protocol | OpenID Connect | OAuth 2.0 only (no ID token) | OpenID Connect | OpenID Connect | OAuth 2.0, or OpenID Connect when openid is requested |
| Endpoints from | Preset | Preset (Authority for Enterprise Server) | Preset (Authority and Tenant) | Preset (Authority) | Authority discovery and ProviderResolved |
| Default scopes | openid email profile | read:user user:email | openid profile email | openid profile email | openid profile email |
Subject claim (Identity.Subject) | sub | id | oid | sub | sub |
Name claim (Identity.Name) | email | login | preferred_username | preferred_username, nickname, email, name | preferred_username, email, name |
| Refresh token | Only with OfflineAccess | When GitHub issues one | With OfflineAccess | Always | With OfflineAccess |
| PKCE | Yes | github.com only | Yes | Yes | Yes |
| Client secret | Required | Required | Required for the browser flows | Confidential app; None for a non-confidential one | Optional |
Prompt | All values (Login sent as select_account) | SelectAccount only | All values | Not sent | All values |
DomainHint | hd, enforced | Ignored | domain_hint | Ignored | Ignored |
LoginHint (in SigningIn) | login_hint | login | login_hint (not with SelectAccount) | Not sent | login_hint |
Revocation (SignOut(revokeTokens: true)) | Yes | Yes | No | Yes | When the provider publishes it |
Provider sign-out (signOutAtProvider: true) | No | No | Yes | No | When the provider publishes it |
The client id and secret for each provider can come from the property, from WISEJ_OAUTH_<PROVIDER>_CLIENT_ID / _CLIENT_SECRET environment variables, from the application configuration, or from a secrets file. The samples below use environment variables for the secret; see Client id and secret for all four sources.
The redirect URI
Every provider asks for the redirect URI (also called callback URL) when you register your application, and compares the one the component sends with it exactly — scheme, host, port, path and letter case. Do not guess it: run the application and read the component's ResolvedRedirectUri, which returns exactly what the component will send for the current configuration.
// temporarily, on the login page: log the value to register with the provider.
Trace.TraceInformation("Register this redirect URI: {0}", this.oAuthClient1.ResolvedRedirectUri);
How the value is computed:
| Configuration | ResolvedRedirectUri |
|---|---|
RedirectUri set | RedirectUri, as set. It is not second-guessed. |
FlowMode = Popup | The relay page under the application root: https://app.example.com/resource.wx/Wisej.Framework/OAuthCallback.html. |
FlowMode = Redirect | The application's startup URL. At the origin root, the entry page your configuration file names is appended: https://app.example.com/Default.html. |
An IOAuthLauncher handles the host | RedirectUri, as set — often a custom scheme. Nothing is computed. |
| Design mode, or no session | An empty string. |
In Redirect mode the property returns null when no registrable value can be computed, and writes a warning to the log naming the problem:
- the application runs at the origin root and there is no configuration, or it names no entry page;
- the application runs in a folder below the origin root (
https://example.com/myapp/), which each host rewrites differently; - the last path segment has no file extension (a folder or a route).
In those cases set RedirectUri explicitly to the full address of the entry page, such as https://example.com/myapp/Default.html, and register that.
The computed value comes from the request the server receives. Behind a proxy or load balancer that terminates TLS, that request is http, and the component refuses an http redirect URI on any host other than a loopback address. Set RedirectUri to the public https address.
Registration rules shared by every provider: the URI is https except on localhost, it carries no fragment, and it matches exactly. Register one URI per flow mode and environment — for example https://localhost:44300/Default.html for development and https://app.example.com/Default.html for production. When the popup is blocked, Popup mode falls back to a redirect against the same relay URI, so it needs no second registration.
Google
Register: in the Google Cloud console, under APIs & Services > Credentials, create an OAuth client ID of type Web application. Add the value of ResolvedRedirectUri to Authorized redirect URIs. Copy the client id and the client secret. Configure the OAuth consent screen with the scopes you request.
| Setting | Behaviour |
|---|---|
| Endpoints | Fixed: accounts.google.com and googleapis.com. The issuer is accepted as https://accounts.google.com or accounts.google.com. |
| Scopes | openid email profile by default. Add Google API scopes, such as https://www.googleapis.com/auth/calendar.readonly, to Scopes or in SigningIn. |
| Identity | Subject is sub; Name is the email claim; EmailVerified is Google's email_verified; TenantId is the hd claim of a Google Workspace account. |
| Refresh token | Only with OfflineAccess = true, which sends access_type=offline. Google issues a refresh token only when it asks for consent, so with Prompt left at Default the component also sends prompt=consent. With Prompt set to None, Login or SelectAccount, an account that has already consented gets no refresh token. |
ClientAuthenticationMethod | ClientSecretPost (default) or ClientSecretBasic. None is rejected: Google always requires the secret. |
Prompt | None, Consent and SelectAccount are sent as-is. Google has no login value, so Login is sent as select_account. |
DomainHint | Sent as hd, and the ID token's hd claim must equal it — the restriction is enforced, not merely suggested. A raw hd in AuthorizationParameters is not enforced. |
| Sign-out | revokeTokens revokes at Google's revocation endpoint. Google has no end-session endpoint, so signOutAtProvider does nothing. |
// Google Workspace only, for the example.com organization.
this.oAuthClient1.Provider = OAuthProvider.Google;
this.oAuthClient1.ClientId = "<your-client-id>.apps.googleusercontent.com";
this.oAuthClient1.DomainHint = "example.com";
this.oAuthClient1.OfflineAccess = true;
// client secret: environment variable WISEJ_OAUTH_GOOGLE_CLIENT_SECRET
GitHub
Register: in GitHub, under Settings > Developer settings > OAuth Apps, create a New OAuth App (an OAuth App, not a GitHub App). Set the Authorization callback URL to the value of ResolvedRedirectUri; register each further URI (the Popup relay page, another environment) as a callback URL of its own. Generate a client secret.
| Setting | Behaviour |
|---|---|
| Protocol | OAuth 2.0 only: no discovery document, no ID token, no nonce. The identity comes from GET https://api.github.com/user and /user/emails. |
| Scopes | read:user user:email by default. Add read:org, repo and so on for the API calls you make. |
| Identity | Subject is the numeric account id; Name is the login; DisplayName is the user's name, falling back to the login; Picture is the avatar. Email is the primary verified address from /user/emails, with EmailVerified set. |
| Refresh token | Kept whenever GitHub returns one. Applications with expiring user tokens get access tokens that live eight hours plus a refresh token, whose own expiry GitHub also reports; the component refreshes transparently. |
ClientAuthenticationMethod | ClientSecretPost (default), the only method GitHub documents. None is rejected: GitHub always requires the secret. |
Prompt | Only SelectAccount is honoured; the other values are ignored. |
LoginHint | Sent as login. |
DomainHint | Ignored. |
| Sign-out | revokeTokens calls DELETE /applications/{client_id}/token with the client credentials. GitHub has no end-session endpoint. |
GitHub Enterprise Server: set Authority to your server's address, such as https://github.example.com. The endpoints move to that host and its /api/v3 REST path. PKCE is supported by no Enterprise Server version, so it is turned off there automatically.
this.oAuthClient1.Provider = OAuthProvider.GitHub;
this.oAuthClient1.ClientId = "<your-client-id>";
this.oAuthClient1.Scopes = new[] { "read:user", "user:email", "read:org" };
// client secret: environment variable WISEJ_OAUTH_GITHUB_CLIENT_SECRET
Signing in with GitHub proves only that the user owns a GitHub account. To admit members of your organization only, check membership against your own records in the Authenticating event, or call the GitHub API with the access token after Authenticated and sign the user out when the check fails.
Microsoft Entra ID
Register: in the Microsoft Entra admin center (or the Azure portal), under App registrations, create a New registration. Choose the Supported account types to match the Tenant you will use. Under Authentication, add a platform of type Web — never Single-page application — and enter the value of ResolvedRedirectUri. Under Certificates & secrets, create a client secret. The Application (client) ID on the overview page is the ClientId.
Entra will not redeem a code for a URI registered as a single-page application unless the token request carries an Origin header, and the component's server-to-server exchange never sends one. A Web-platform URI in turn requires a client credential, so OAuthClientAuthenticationMethod.None fails at the token endpoint for the Redirect and Popup flows.
Entra's own rules for redirect URIs: they are case-sensitive, at most 256 characters, may not carry a query string when the registration includes personal Microsoft accounts, and on localhost the port is ignored — do not register two URIs that differ only by port.
| Setting | Behaviour |
|---|---|
Tenant | Which accounts may sign in. A tenant id (GUID), a verified domain of the tenant such as contoso.onmicrosoft.com, or one of the aliases common (the default: work, school and personal accounts), organizations (work and school) or consumers (personal). A domain is resolved to its tenant id through the tenant's OpenID Connect metadata when the first sign-in completes, and cached for 24 hours. |
Authority | The Entra instance. Null means https://login.microsoftonline.com; for a national cloud, its host, such as https://login.microsoftonline.us. The MSAL shape https://login.microsoftonline.com/<tenant> is accepted when Tenant is empty (or equal to that segment). A segment that conflicts with Tenant, or more than one path segment, fails the sign-in with OAuthError.Configuration. |
AllowedTenants | The tenant ids admitted under a multi-tenant alias. See below. |
| Scopes | openid profile email by default. Add Microsoft Graph scopes, such as User.Read, for the API calls you make. |
| Identity | Subject is oid, because Entra's sub differs per application; Name is preferred_username; TenantId is tid. Email may be absent and is never marked verified. |
| Refresh token | With OfflineAccess = true, which adds the offline_access scope. |
ClientAuthenticationMethod | ClientSecretPost (default) or ClientSecretBasic. None only for a launcher host whose redirect URI is registered as a public client. |
Prompt | All values are sent. With SelectAccount, the login hint is dropped, because Entra rejects the two together. |
DomainHint | Sent as domain_hint, to skip the account picker and go straight to that organization's sign-in page. |
RequestUserInfo | When true, the userinfo document is read from Microsoft Graph (https://graph.microsoft.com/oidc/userinfo). |
| Sign-out | Entra has no revocation endpoint, so revokeTokens has no effect and TokensRevoked is false. signOutAtProvider navigates to Entra's logout endpoint; register the postLogoutRedirectUri you pass in the app registration as well. |
// single tenant: only accounts of the contoso.com organization.
this.oAuthClient1.Provider = OAuthProvider.Entra;
this.oAuthClient1.ClientId = "<application-client-id>";
this.oAuthClient1.Tenant = "contoso.onmicrosoft.com";
this.oAuthClient1.Scopes = new[] { "openid", "profile", "email", "User.Read" };
this.oAuthClient1.OfflineAccess = true;
// client secret: environment variable WISEJ_OAUTH_ENTRA_CLIENT_SECRET
Multi-tenant applications and AllowedTenants
With Tenant set to common or organizations, every Microsoft tenant in the world can sign in. That is right for a public SaaS application and wrong for almost anything else. Restrict it with AllowedTenants:
// multi-tenant registration, admitting the tenants of two customers only.
this.oAuthClient1.Provider = OAuthProvider.Entra;
this.oAuthClient1.ClientId = "<application-client-id>";
this.oAuthClient1.Tenant = "organizations";
this.oAuthClient1.AllowedTenants = new[]
{
"11111111-1111-1111-1111-111111111111", // customer A's tenant id
"22222222-2222-2222-2222-222222222222", // customer B's tenant id
};
- The check is made before any claim is trusted: a token whose
tidis not listed fails withOAuthError.InvalidToken. - The expected tenant is never taken from the token. It is the tenant you configured or, under an alias, the
AllowedTenantsentry that matches; the issuer andtidare checked against that value. - Entries are tenant ids (GUIDs, in any letter case). A verified domain is not accepted here, because the ID token names its tenant by id only: an entry that is not a GUID fails the sign-in with
OAuthError.Configurationbefore the user is sent to Microsoft. - With an alias and
AllowedTenantsleft null, every tenant is accepted and the component writes one warning per instance to the log, naming the property. AllowedTenantsis ignored whenTenantpins one tenant.
If you key user records on Subject, key them on TenantId as well when you admit more than one tenant.
National clouds
Set Authority to the cloud's instance host; the endpoints and the expected issuer follow it. The userinfo endpoint is an absolute Microsoft Graph address; if you set RequestUserInfo on a national cloud, point e.UserInfoEndpoint at that cloud's Graph in a ProviderResolved handler.
this.oAuthClient1.Provider = OAuthProvider.Entra;
this.oAuthClient1.Authority = "https://login.microsoftonline.us";
this.oAuthClient1.Tenant = "<tenant-id>";
GitLab
Register: on gitlab.com or your own instance, under User Settings > Applications (or a group's or the admin area's Applications), add a new application. Enter the value of ResolvedRedirectUri as the redirect URI — several may be entered, one per line, each matched exactly. Tick the openid, profile and email scopes, and leave Confidential ticked for a server application. Copy the Application ID (the client id) and the Secret.
| Setting | Behaviour |
|---|---|
Authority | Null means https://gitlab.com. For a self-managed instance, its external URL including any relative root path, such as https://example.com/gitlab: the issuer is compared with it exactly. |
| Endpoints | Composed from Authority (/oauth/authorize, /oauth/token, /oauth/userinfo, /oauth/discovery/keys, /oauth/revoke). GitLab publishes a discovery document, but the preset is used. |
| Scopes | openid profile email by default. Add read_api or read_user for API calls. |
| Identity | Subject is sub; Name is the first of preferred_username, nickname, email, name. The userinfo endpoint is always read, because self-managed instances before about version 16.6 put the profile claims there and not in the ID token. Email is present only when the user has a public email. |
| Refresh token | Always issued. offline_access is not a GitLab scope, so OfflineAccess adds nothing. |
ClientAuthenticationMethod | ClientSecretPost (default) for a confidential application; None for a non-confidential one, which authenticates with PKCE alone. |
Prompt, LoginHint | Not sent: GitLab does not implement login_hint, and some versions fail on prompt values. If your instance handles them, add them through AuthorizationParameters. |
DomainHint | Ignored. |
| Sign-out | revokeTokens revokes at /oauth/revoke. GitLab has no end-session endpoint. |
// self-managed GitLab installed under a relative root.
this.oAuthClient1.Provider = OAuthProvider.GitLab;
this.oAuthClient1.Authority = "https://example.com/gitlab";
this.oAuthClient1.ClientId = "<application-id>";
// client secret: environment variable WISEJ_OAUTH_GITLAB_CLIENT_SECRET
Custom OAuth 2.0 / OpenID Connect provider
OAuthProvider.OAuth2 works with Keycloak, Auth0, Okta, Duende IdentityServer, Amazon Cognito and any other server that follows the standards. Register a confidential (or "regular web application") client with the value of ResolvedRedirectUri as its redirect URI.
With discovery
Set Authority to the provider's issuer URL. The component reads {Authority}/.well-known/openid-configuration, checks that the document publishes the expected issuer, takes the endpoints from it, and caches it for 24 hours.
// Keycloak realm.
this.oAuthClient1.Provider = OAuthProvider.OAuth2;
this.oAuthClient1.Authority = "https://sso.example.com/realms/staff";
this.oAuthClient1.ClientId = "wisej-app";
this.oAuthClient1.OfflineAccess = true;
// client secret: environment variable WISEJ_OAUTH_OAUTH2_CLIENT_SECRET
A discovery document that cannot be fetched, is not a JSON object, or does not publish the expected issuer fails the sign-in with OAuthError.Configuration.
Patching endpoints with ProviderResolved
ProviderResolved is raised after discovery and before anything is used; values assigned there win. Use it to fix a provider that publishes something wrong, to route the token endpoint through a proxy, or to name the claim that identifies the user:
private void oAuthClient1_ProviderResolved(object sender, OAuthProviderResolvedEventArgs e)
{
// the provider's user document carries the identifier as "user_id".
e.SubjectClaim = "user_id";
// and the display name under "display_name".
e.NameClaimType = "display_name";
}
Without discovery
A plain OAuth 2.0 server has no discovery document. Leave Authority empty and supply the endpoints in ProviderResolved. Without the openid scope there is no ID token, so the identity comes from the userinfo endpoint, which is then always called:
public LoginPage()
{
InitializeComponent();
this.oAuthClient1.Provider = OAuthProvider.OAuth2;
this.oAuthClient1.ClientId = "<your-client-id>";
this.oAuthClient1.Scopes = new[] { "profile" }; // no "openid": plain OAuth 2.0
}
private void oAuthClient1_ProviderResolved(object sender, OAuthProviderResolvedEventArgs e)
{
e.AuthorizationEndpoint = "https://auth.example.com/oauth/authorize";
e.TokenEndpoint = "https://auth.example.com/oauth/token";
e.UserInfoEndpoint = "https://api.example.com/me";
e.RevocationEndpoint = "https://auth.example.com/oauth/revoke";
e.SubjectClaim = "id";
}
With openid among the scopes, the component also needs Issuer and JwksUri (from discovery or from the handler), and then validates the ID token, the nonce and the signature exactly as for the built-in providers.
| Setting | Behaviour |
|---|---|
| Scopes | openid profile email by default. OpenID Connect validation applies when openid is requested. |
| Identity | Subject is sub unless SubjectClaim says otherwise; Name is the first of preferred_username, email, name, or the one claim NameClaimType names. A subject the provider did not send fails with OAuthError.UserInfoRequestFailed. |
| Refresh token | With OfflineAccess = true, which adds the offline_access scope. |
ClientAuthenticationMethod | ClientSecretPost (default), ClientSecretBasic, or None for a public client. |
Prompt, LoginHint | Sent as prompt and login_hint. |
DomainHint | Ignored. Put a provider-specific hint in AuthorizationParameters. |
| Sign-out | RFC 7009 revocation when the provider publishes a revocation endpoint; RP-initiated logout, with id_token_hint, when it publishes an end-session endpoint. |
Every endpoint — from discovery or from your handler — must be https unless its host is a loopback address. An http endpoint is refused before any request is sent, and there is no opt-out.
With Authority set, the component fetches the discovery document once every 24 hours even when your handler replaces every endpoint, because discovery is decided before the event is raised. A component that must not discover leaves Authority empty and supplies all the endpoints, the issuer and the key set in ProviderResolved.