A starter project for the following tech stack:
- IdentityServer4
- ASP.NET Core
- NGINX
- HTTPS
- Docker
docker-compose up
You can make http requests. For this, I use postman:
Get the openid configuration:
GET https://localhost/authentication/.well-known/openid-configuration
Get an access token:
POST https://localhost/authentication/connect/token
--- Request Body ---
client_id=SampleApp.Mobile
client_secret=secret
username=ben
password=password
scope=openid SampleApp.API
grant_type=password
Response:
{
"access_token": "token",
"expires_in": 2592000,
"token_type": "Bearer"
}
You can now make requests against the API:
GET https://localhost/api/identity
--- Headers ---
Authorization: Bearer token
If you don't add the Authorization
header, you will get a 401.
Docker is set up to only run the app. To debug this, you will need to change the following lines:
In SampleApp.Authentication/Startup.cs, comment out the line like below:
// options.PublicOrigin = "http://localhost:4000";
In SampleApp.API/Startup.cs, replace the Authority
:
AddIdentityServerAuthentication(options =>
{
options.Authority = "http://localhost:4000/authentication";
options.RequireHttpsMetadata = false;
options.ApiName = "SampleApp.API";
});
In a real project, you would set these values in a configuration file, so you might have something like:
appsettings.json
- development configurationsappsettings.Staging.json
- docker development configurationappsettings.Production.json
- docker production configurations
You would then want to reproduce this pattern for nginx.conf
, docker-compose
and Dockerfile
.