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

Interop with the Microsoft Graph SDK - DelegateAuthenticationProvider missing #1155

Open
1 task done
raclettierer opened this issue Apr 10, 2023 · 4 comments
Open
1 task done
Labels
area: documentation 📖 Improvements or additions to documentation help wanted Extra attention is needed

Comments

@raclettierer
Copy link

Category

  • Bug

Describe the bug

After updating the solution to the new microsoft graph library the interop code not working any more. The DelegateAuthenticationProvider is missing

Steps to reproduce

  1. Update to Microsoft.Graph V 5.*
  2. using code for interop: https://pnp.github.io/pnpcore/using-the-sdk/basics-graphsdk.html

Expected behavior

Environment details (development & target environment)

Additional context

@jansenbe jansenbe added area: documentation 📖 Improvements or additions to documentation help wanted Extra attention is needed labels Apr 17, 2023
@jansenbe
Copy link
Contributor

jansenbe commented Apr 17, 2023

@raclettierer , thanks for raising this. We indeed did not test with the v5 Graph SDK.

@TashunkoWitko
Copy link

TashunkoWitko commented Jul 6, 2023

See https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/feature/5.0/docs/upgrade-to-v5.md#authentication

This worked for me:
`public class GraphTokenProvider : IAccessTokenProvider
{
private readonly PnPContext _pnpContext;
public GraphTokenProvider(PnPContext context)
{
_pnpContext = context;
AllowedHostsValidator = new AllowedHostsValidator();
}

    public AllowedHostsValidator AllowedHostsValidator { get; }

    public Task<string> GetAuthorizationTokenAsync(Uri uri, Dictionary<string, object>? additionalAuthenticationContext = null, CancellationToken cancellationToken = default)
    {
        return _pnpContext.AuthenticationProvider.GetAccessTokenAsync(new Uri("https://graph.microsoft.com"));
    }
}`

var accessTokenProvider = new BaseBearerTokenAuthenticationProvider(new GraphTokenProvider(pnpContext)); var graphServiceClient = new GraphServiceClient(accessTokenProvider);

@jansenbe
Copy link
Contributor

@TashunkoWitko : thanks for sharing this, I'll incorporate that in our docs.

@heinrich-ulbricht
Copy link

heinrich-ulbricht commented Dec 26, 2023

Stumbled upon this issue after upgrading to Graph SDK v5 that obsoleted the DelegateAuthenticationProvider.

Will the pnpContext.AuthenticationProvider.GetAccesstokenAsync get a new token every time or does it handle token caching and lifetimes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: documentation 📖 Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants