Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AuthenticationProvider Issue with Entra ID #515

Open
fuegans4213 opened this issue Jan 24, 2025 · 0 comments
Open

AuthenticationProvider Issue with Entra ID #515

fuegans4213 opened this issue Jan 24, 2025 · 0 comments

Comments

@fuegans4213
Copy link

Hello i'm facing issues usign the authProvider to use with my Kiota Client API,

i'm using a Blazor Server App ,

My authentication is buld like this :

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(options =>
    {
        builder.Configuration.Bind("AzureAd", options);

        // Request a refresh_token.
        options.Scope.Add(OpenIdConnectScope.OfflineAccess);
        // Store the refresh_token.

        options.SaveTokens = true;


        options.Events.OnTokenValidated += eventArgs =>
        {
            Console.WriteLine("OnTokenValidated");
            var idToken = eventArgs.ProtocolMessage.IdToken;
            //Acces to the access_token from here ???
            return Task.CompletedTask;
        };

        options.SaveTokens = true;

    })
        .EnableTokenAcquisitionToCallDownstreamApi()
        .AddInMemoryTokenCaches();

I'm using a CustomTokenCredential configuration

    private readonly string _accessToken;

    public CustomTokenCredential(string accessToken)
    {
        _accessToken = accessToken;
    }

    public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken)
    {
        return new AccessToken(_accessToken, DateTimeOffset.UtcNow.AddHours(1));
    }

    public override async ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
    {
        // Return the token asynchronously.
        return await Task.FromResult(new AccessToken(_accessToken, DateTimeOffset.UtcNow.AddHours(1)));
    }
}

But i m not able to connect using that DI configuration :

var tokenCredential = new CustomTokenCredential(AccesToken);

var provider = new AzureIdentityAuthenticationProvider(tokenCredential);
builder.Services.AddSingleton<IRequestAdapter, HttpClientRequestAdapter>(adapter =>
{
    var authProvider = new AzureIdentityAuthenticationProvider(tokenCredential);
    return new HttpClientRequestAdapter(authProvider)
    {
        BaseUrl = basePath,
    };
});

builder.Services.AddSingleton<MyClient>();

Could you help me resolve this or show me the proper way to approach it?

@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs Triage 🔍
Development

No branches or pull requests

1 participant