Giter Site home page Giter Site logo

microsoft / kiota-authentication-azure-dotnet Goto Github PK

View Code? Open in Web Editor NEW
5.0 19.0 6.0 327 KB

Kiota authentication provider implementation with Azure Identity

Home Page: https://aka.ms/kiota/docs

License: MIT License

C# 69.11% PowerShell 26.11% Dockerfile 4.78%
kiota authentication azure identity openapi dotnet

kiota-authentication-azure-dotnet's Introduction

Kiota Azure Identity authentication provider library for dotnet

Build and Test NuGet Version

The Kiota Azure Identity authentication provider library for dotnet is the authentication provider implementation with Azure.Identity.

A Kiota generated project will need a reference to a authentication provider library to authenticate HTTP requests to an API endpoint.

Read more about Kiota here.

Using Azure Identity authentication provider library for dotnet

dotnet add package Microsoft.Kiota.Authentication.Azure --prerelease

Debugging

If you are using Visual Studio Code as your IDE, the launch.json file already contains the configuration to build and test the library. Otherwise, you can open the Microsoft.Kiota.Authentication.Azure.sln with Visual Studio.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

kiota-authentication-azure-dotnet's People

Contributors

andrueastman avatar baywet avatar czemacleod avatar dependabot[bot] avatar github-actions[bot] avatar hwoodiwiss avatar microsoft-github-operations[bot] avatar microsoftopensource avatar samwelkanda avatar schuettecarsten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kiota-authentication-azure-dotnet's Issues

AzureIdentityAccessTokenProvider.GetAuthorizationTokenAsync

Method AzureIdentityAccessTokenProvider.GetAuthorizationTokenAsync will add the current uri to the instance variable _scopes. This is not thread-safe and might cause InvalidOperationExceptions because of collections that are modified concurrently. It also uses the current method parameter uri to initialize the instance variable. Next time, when a different uri is used, scopes might be wrong.

My exception:

System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
at bool System.Collections.Generic.HashSet.AddIfNotPresent(T value, out int location)
at async Task Microsoft.Kiota.Authentication.Azure.AzureIdentityAccessTokenProvider.GetAuthorizationTokenAsync(Uri uri, Dictionary additionalAuthenticationContext, CancellationToken cancellationToken)
at async Task Microsoft.Kiota.Abstractions.Authentication.BaseBearerTokenAuthenticationProvider.AuthenticateRequestAsync(RequestInformation request, Dictionary additionalAuthenticationContext, CancellationToken cancellationToken)
at async Task Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.GetHttpResponseMessage(RequestInformation requestInfo, CancellationToken cancellationToken, Activity activityForAttributes, string claims)
at async Task Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync(RequestInformation requestInfo, ParsableFactory factory, Dictionary> errorMapping, CancellationToken cancellationToken)
at async Task Microsoft.Graph.Users.UsersRequestBuilder.GetAsync(Action requestConfiguration, CancellationToken cancellationToken)
[...]

Current implementation:

        if(!_scopes.Any())
            _scopes.Add($"{uri.Scheme}://{uri.Host}/.default");
        span?.SetTag("com.microsoft.kiota.authentication.scopes", string.Join(",", _scopes));
        var result = await this._credential.GetTokenAsync(new TokenRequestContext(_scopes.ToArray(), claims: decodedClaim), cancellationToken);

Idea to fix this is to not modify _scopes instance variable but use a local array:

        string[] scopes = _scopes.ToArray();
        if (scopes.Length == 0)
            sopes = new string[] { $"{uri.Scheme}://{uri.Host}/.default" };
        span?.SetTag("com.microsoft.kiota.authentication.scopes", string.Join(",", scopes));
        var result = await this._credential.GetTokenAsync(new TokenRequestContext(scopes, claims: decodedClaim), cancellationToken);

AzureIdentityAccessTokenProvider incorrect docs

AzureIdentityAccessTokenProvider incorrectly proclaims it's association with IAuthenticationProvider, to the detrement of trying to use it.

In short, the docs are wrong

namespace Microsoft.Kiota.Authentication.Azure;
/// <summary>
/// Provides an implementation of <see cref="IAuthenticationProvider"/> for Azure.Identity.
/// </summary>
public class AzureIdentityAccessTokenProvider : IAccessTokenProvider, IDisposable

It does, in fact, not provide an implementation of IAuthenticationProvider for Azure.Identity. I don't know which is supposed to be right, the code or the docs, so I'm leaving it in your capable hands to decide.

Thanks, Lena

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.