Blazor > Web API RRS feed

  • Question

  • User1352387630 posted

    Hi All,

    I'm looking for some advice or confirmation that I am going down the right path.

    I have a B2C directory that I will be using for my system.  The system will consist of a WebAPI and a Blazer Server Side app.  I'm using all the latest .net core 3.0 templates.  Is my thinking correct? The webapi and blazor app are two seperate app registrations in my b2c directory.

    The Blazor app and the Webapi will both use Azure B2C for auth.  What I'm trying to do is that once the user auths to the blazor app, when the user executes a function that calls the webapi, I want to use the logged in user's (in the blazor app) context to call the webapi... 

    I got my webapi and my blazor app configured to use B2C with no issues... but there's a few things I need some direction on:

    1. First... am I doing this correctly?
    2. When calling the Webapi, I of course need to provide an access token in the httpclient I use to call the api.  The blazor app does not have the user claims access_token... Is this thought correct, and is it correct in thinking I need to go get an access token from graph api before I can call the webapi? 
    3. Can I get the access_token when logging into the blazor app?
    4. is it correct to assume the access token I use should be valid to call the webapi, or should I request a token specifically for the webapi?

    I'm looking at calling my webapi through something like this (Still playing with it so this might be totally wrong)

            HttpClient client = new HttpClient();
            var test4 = httpContextAccessor.HttpContext;
            var authState = AuthenticationStateProvider.GetAuthenticationStateAsync();
            var user = authState.Result.User;
    //Looking at using something like this to get an access token.... //var token = user.Claims["access_token"]; Uri ServiceBaseUri = new Uri("https://mywebapi.com/"); myapp.server.api.swaggerClient t = new myapp.server.api.swaggerClient(ServiceBaseUri.ToString(), client); string currentCount = t.WeatherForecastAsync("test123").Result;

    Last question... Here I am declaring a new Httpclient... Blazor has it's own httpclient.  How can I inject / reference it in a custom class to use the built in httpclient?

    Sunday, November 17, 2019 3:20 AM

All replies

  • User-2062097380 posted
    Did you happen to get the answer to this sorry I'm also looking for this.
    Friday, January 24, 2020 1:07 AM