ASP.NET Core 3 Identity - Adding login from Xamarin Forms

Viewed 323

I'm trying to add a new client to the IdentityServer from the build in packages that comes with the ASP.NET Core 3 and Angular template. After enabling Individual user accounts. The following is my code

Startup.cs

services.AddIdentityServer()
.AddInMemoryClients(Clients.SetupClients())
.AddInMemoryIdentityResources(Clients.GetIdentityResources())
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>()
.AddJwtBearerClientAuthentication();

Clients.cs -> To add the custom client

public class Clients
    {
        public static IEnumerable<Client>  SetupClients()
        {
            var client = new Client
            {
                ClientId = "MobileApp",
                ClientSecrets = {new Secret("secret".Sha256())},
                ClientUri = "xamarin-auth://localhost",
                AccessTokenType = AccessTokenType.Jwt,

                AllowedGrantTypes = GrantTypes.Hybrid,
                AllowedScopes = {"AdvancedSoftware.SmartRestaurant.WebAppAPI","openid","profile"}
            };
            var clients = new List<Client>();
            clients.Add(client);
            return clients;
        }
        public static List<IdentityResource> GetIdentityResources()
        {
            return new List<IdentityResource>
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile() // <-- usefull
            };
        }
    }

After doing a request to /connect/authorize with the following parameters:

https://localhost:5001/connect/authorize?client_id=MobileApp&redirect_uri=xamarin-auth:%2F%2Flocalhost&scope=openid%20profile&response_type=token&state=gnonhwgumouubqehconnect/token?client_id=MobileApp&redirect_uri=xamarin-auth:%2F%2Flocalhost&scope=openid profile&response_type=token&state=gnonhwgumouubqeh&client_secret=--hidden--

The error from the Debug:

IdentityServer4.Validation.AuthorizeRequestValidator[0]
      Unknown client or not enabled: MobileApp
      {
        "SubjectId": "anonymous",
        "RequestedScopes": "",
        "Raw": {
          "client_id": "MobileApp",
          "redirect_uri": "xamarin-auth://localhost",
          "scope": "openid profile",
          "response_type": "token",
          "state": "gnonhwgumouubqehconnect/token?client_id=MobileApp",
          "client_secret": "-hidden-"
        }

It always return the client is not defined although it is added. I tried many other examples and none seems to work.

0 Answers
Related