I would like to query some data from a winforms application.
I secured the odata described in the documentation:
With a valid token I am able to query data from the winforms application.
But I am not able to get the token with a web request or something else?
Maybe you have an url and how to post data to get the token? Thanks.
Radzen Blazor Wasm applications use Identity Server (as the dotnet new template). You can check Identity Server's documentation (or search online) how to get a token from it. The Radzen application itself does not have a dedicated API for this.
the last days I read the documentation but it does not work for me.
Is there another way to consume the radzen api with the users?
Now I am using the lightswitch odata, this is very easy to authenticate.
I use the winforms app and the server app local, so security is not very imported.
I have to login and to track changes from users.
Thanks.
I need a token to query the odata if it is secured.
With Lightswitch Odata it is very easy to log in a user.
With radzen and identity server it is more complex. The navigationmanager handles the login and the redirect.
I tried really many different requests with the httpclient from winforms to get the token, but it does not work. I cannot find the method on the server which creates the token for the user. Otherwise it would be possible to make a request with username and password and send the token back.
I think the identity server uses for this the authentication.js file?
Thanks.
But in the radzen project is no config.cs for defining the clients?
I found the clientid in the mssql table PersistedGrants and a key.
Is this key the client secret?
I tried to get a token from my winforms app with the client id and the secret and it works.
But I would to have a token for my radzen users.
For example I have the user markus@gmail.com with my password.
I tried to get a token with the user and password, but there is an error that the client is unauthorized.
Maybe I have to add the users also to the identity server, but how?
Thanks.
In the client in the config File I had to change the AllowedGrantTypes to GrantTypes.ResourceOwnerPassword
public static IEnumerable<IdentityServer4.Models.Client> Clients =>
new List<IdentityServer4.Models.Client>
{
new IdentityServer4.Models.Client
{
ClientId = "client",
// no interactive user, use the clientid/secret for authentication
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
// secret for authentication
ClientSecrets =
{
new Secret("secret".Sha256())
},
// scopes that client has access to
AllowedScopes = { "api1" }
}
};
Following Code I am using in my Winforms Application:
When I add the client in the appsettings.json I have to add the inmemoryclients in the startup.cs. This will override the standard users. So it is not possible.
I tried to add the client in te costum startup but it is not possible with my code, because it is adding another IdentityServer and this is not possible.
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationIdentityDbContext>(options =>
options.Clients.Add(new IdentityServer4.Models.Client()
{
ClientId = "client",
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
AccessTokenType = AccessTokenType.Jwt,
ClientSecrets =
{
new Secret("secret".Sha256())
},
// scopes that client has access to
AllowedScopes = { "TestwbaSecurity.ServerAPI openid profile" }
}));
But I do not know how to access the options of the ApiAuthorization in the Custom startup? Because in the options of the Apiauthorization I have to add the client.
Maybe you can help me with this? Thanks.
As far as I understand IdentityServer's configuration you should be able to add multiple clients from the appsettings.json file without the need for inmemoryclients. I am not sure why it isn't working for you as I lack the required IdentityServer experience.