This repo provides a basic demo web application, created using ASP.NET, and demonstrates how to add authentication features with Authgear by implementing an OpenID Connect flow, then retrieving OAuth tokens, in order to call APIs.
Authgear acts as an IAM provider that is a gatekeeper to the resources you provide to customers as web and mobile applications, APIs, etc. The gatekeeper initiates authorization as outlined in OAuth 2.0. The addition of the OpenID Connect layer adds authentication to secure your users’ digital identities and your product.
Before you get started, you will need the following:
- A free Authgear account. Sign up if you don't have one already.
- .NET 7 downloaded and installed on your machine. You can also use Visual Studio and VS code to automatically detect the .NET version.
- Create Authgear OIDC Client App to use it as an OpenID Connect Provider.
Start by cloning the project into your local machine:
git clone https://github.com/authgear/authgear-example-dotnet.git
Make the project directory your current working directory:
cd authgear-example-dotnet
Update the following configuration variables in the appsettings.json
file with your Authgear app settings values from Authgear OIDC Client application such as Issuer
, ClientId
, ClientSecret
, and Authgear endpoint:
{
"OpenIDConnect": {
"ClientId": "{your-client-id}",
"ClientSecret": "{your-client-secret}",
"Issuer": "{your-authgear-app-endpoint}",
"Scope": "openid offline_access",
"PostLogoutRedirectUri": "http://localhost:5002",
"TokenEndpoint": "{your-authgear-app-endpoint}/oauth2/token"
},
"Urls": "http://localhost:5002",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
Execute the following command to run the ASP.NET Core web application:
dotnet build
dotnet run
You can now visit http://localhost:5002 to access the application. When you click on the "View Protected Data" button, ASP.NET Core takes you to the Authgear’s Login page.