I'm currently having an issue with attempts to get the access token from the IdentityServer4 instance which is containerized with the docker. What's strange, is that it works when I run the IdentityServer intance locally. I'm using the AspNetCoreIdentity template.
After I enter the login infomation, The application just redirects me to the login page. It happens on the Redirect(model.ReturnUrl) line with the ReturnUrl value being "/connect/authorize/callback?response_type=code&state&client_id=postman-api&scope=postman.api&redirect_uri=https%3A%2F%2Fwww.getpostman.com%2Foauth2%2Fcallback"
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Login(LoginInputModel model, string button)
{
var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl);
...
if (ModelState.IsValid)
{
var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberLogin, lockoutOnFailure: true);
if (result.Succeeded)
{
var user = await _userManager.FindByNameAsync(model.Username);
await _events.RaiseAsync(new UserLoginSuccessEvent(user.UserName, user.Id, user.UserName, clientId: context?.ClientId));
if (context != null)
{
...
return Redirect(model.ReturnUrl);
}
...
}
Here are the code and the configuration files:
The client and apis configuration:
public static IEnumerable<ApiResource> GetApis() { return new ApiResource[] { new ApiResource("basket.api", "Basket Api"), new ApiResource("postman.api", "Postman Test Resource") }; } public static IEnumerable<Client> GetClients() { return new[] { new Client { ClientId = "postman-api", ClientName = "Postman client", AllowAccessTokensViaBrowser = true, RequireConsent = false, RedirectUris = {"https://www.getpostman.com/oauth2/callback"}, PostLogoutRedirectUris = {"https://www.getpostman.com"}, AllowedCorsOrigins = {"https://www.getpostman.com"}, EnableLocalLogin = true, AllowedGrantTypes = GrantTypes.Code, ClientSecrets = { new Secret("SomeValue".Sha256()) }, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile, "postman.api", "basket.api" } } }; }
The dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
WORKDIR /src
COPY ["Auth2.2/Auth2.2.csproj", "Auth2.2/"]
RUN dotnet restore "Auth2.2/Auth2.2.csproj"
COPY . .
WORKDIR "/src/Auth2.2"
RUN dotnet build "Auth2.2.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Auth2.2.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Auth2.2.dll"]
- The IdentityServer docker configuration from the docker-compose file:
auth2.2:
image: ${DOCKER_REGISTRY-}auth22
build:
context: .
dockerfile: Auth2.2/Dockerfile
ports:
- "5000:80"