Odata Winforms Client Credentials

Hi,

I am consuming the odata source from radzen in a winforms client.

I added the authorization on the server controller

``.
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;

namespace [ApplicationName].Controllers.[DataSourceName]
{
[Authorize(AuthenticationSchemes="Bearer")]
public partial class OrdersController
{
}
}

Now I am not able to consume the data after this.
I used Odata connected service, with this code I am able to consume data wihout security:

var serviceRoot = "http://localhost:8000/radzenapp/odata/database/";
var context = new Default.Container(new Uri(serviceRoot));
List<AufgabenSet> aufgabenSets = context.AufgabenSets.Take(20).ToList();

Maybe there is a code snipte for the authorization in winforms client?

Thanks.

We don’t have much experience with consuming OData services with Bearer authentication from Winforms however this thread might help you:

Thanks for the thread, but it does not work for me.

Is there another authentication via radzen and winforms you know that is working?

Thanks.

Hi @MarkusW,

I’m not aware of any other way - adding Bearer authentication header should work in Winforms as well.

Hi,

now I got it. I started fiddler and copied the access token from user login in the http request and it is working.

But I do not know how to get the accestoken with my user credentials?

Thanks.

Check the implementation of security.service.ts to see how it gets the current token.

Finally I got the code to get the token:

private async Task getTokenAsync()
        {
            var pocoObject = new
            {
                username = "markus",
                password = "123456"
            };

        string json = JsonConvert.SerializeObject(pocoObject);

        StringContent data = new StringContent(json, Encoding.UTF8, "application/json");

        var url = "http://localhost:5000/auth/login";
    
        var client = new HttpClient();

        var response = await client.PostAsync(url, data);

        string result = await response.Content.ReadAsStringAsync();
    }