Skip to content

Commit

Permalink
Fix supported scopes bug (Soluto#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleF83 authored Jul 17, 2019
1 parent 8fb1875 commit fbf2876
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
28 changes: 21 additions & 7 deletions Config.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Security.Claims;
using IdentityServer4;
Expand All @@ -11,9 +13,21 @@ namespace OpenIdConnectServer
{
public static class Config
{
public static IEnumerable<ApiResource> GetApiResources() => new List<ApiResource>{
new ApiResource(Environment.GetEnvironmentVariable("API_RESOURCE")),
};
public static IEnumerable<ApiResource> GetApiResources()
{
string apiResourcesStr = Environment.GetEnvironmentVariable("API_RESOURCES_INLINE");
if (string.IsNullOrWhiteSpace(apiResourcesStr))
{
var apiResourcesFilePath = Environment.GetEnvironmentVariable("API_RESOURCES_PATH");
if (string.IsNullOrWhiteSpace(apiResourcesFilePath))
{
return new List<ApiResource>();
}
apiResourcesStr = File.ReadAllText(apiResourcesFilePath);
}
var apiResourceNames = JsonConvert.DeserializeObject<string[]>(apiResourcesStr);
return apiResourceNames.Select(r => new ApiResource(r));
}

public static IEnumerable<Client> GetClients()
{
Expand All @@ -25,9 +39,9 @@ public static IEnumerable<Client> GetClients()
{
throw new ArgumentNullException("You must set either CLIENTS_CONFIGURATION_INLINE or CLIENTS_CONFIGURATION_PATH env variable");
}
configStr = System.IO.File.ReadAllText(configFilePath);
configStr = File.ReadAllText(configFilePath);
}
var configClients = Newtonsoft.Json.JsonConvert.DeserializeObject<IEnumerable<Client>>(configStr, new SecretConverter());
var configClients = JsonConvert.DeserializeObject<IEnumerable<Client>>(configStr, new SecretConverter());
return configClients;
}

Expand All @@ -48,9 +62,9 @@ public static List<TestUser> GetUsers()
{
return new List<TestUser>();
}
configStr = System.IO.File.ReadAllText(configFilePath);
configStr = File.ReadAllText(configFilePath);
}
var configUsers = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TestUser>>(configStr);
var configUsers = JsonConvert.DeserializeObject<List<TestUser>>(configStr);
return configUsers;
}
}
Expand Down
11 changes: 0 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ WORKDIR /OpenIdConnectServerMock

ENV ASPNETCORE_ENVIRONMENT=Development

# OpenId connect client
ENV OIDC_CLIENT_ID=openid-mock-client
ENV REDIRECT_URIS=http://localhost:3000/auth/oidc

# oauth2/client_credentials client
ENV CLIENT_CREDENTIALS_CLIENT_ID=client-credentials-mock-client
ENV CLIENT_CREDENTIALS_CLIENT_SECRET="client-credentials-mock-client-secret"
ENV API_RESOURCE="some-app"

ENV TEST_USER="{\"SubjectId\":\"1\",\"Username\":\"User1\",\"Password\":\"pwd\"}"

EXPOSE 80

HEALTHCHECK --interval=60s --timeout=2s --retries=8 \
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OpenId Connect Server Mock

This project is the mock server that provides OpenId Connect functionality including Implicit Flow.
This project allows you to run configurable mock server with OpenId Connect functionality.

This is the sample of using the server in `docker-compose` configuration:

Expand All @@ -14,6 +14,10 @@ This is the sample of using the server in `docker-compose` configuration:
- "4011:80"
environment:
ASPNETCORE_ENVIRONMENT: Development
API_RESOURCES_INLINE: |
[
"some-app"
]
USERS_CONFIGURATION_INLINE: |
[
{
Expand Down Expand Up @@ -67,5 +71,5 @@ When `clients-config.json` is as following:

Clients configuration should be provided. Test user configuration is optional (used for implicit flow only).

There are two ways to provide configuration both to clients and users. You can either provide it inline as environment variable (`USERS_CONFIGURATION_INLINE` / `CLIENTS_CONFIGURATION_INLINE`) or mount volume and provide the path to configuration json as environment variable (`USERS_CONFIGURATION_PATH` / `CLIENTS_CONFIGURATION_PATH`).
There are two ways to provide configuration for supported scopes, clients and users. You can either provide it inline as environment variable (`USERS_CONFIGURATION_INLINE` / `CLIENTS_CONFIGURATION_INLINE` / `API_RESOURCES_INLINE`) or mount volume and provide the path to configuration json as environment variable (`USERS_CONFIGURATION_PATH` / `CLIENTS_CONFIGURATION_PATH` / `API_RESOURCES_PATH`).

0 comments on commit fbf2876

Please sign in to comment.