pnp / pnpcore

The PnP Core SDK is a modern .NET SDK designed to work for Microsoft 365. It provides a unified object model for working with SharePoint Online and Teams which is agnostic to the underlying API's being called
https://aka.ms/pnp/coresdk/docs
MIT License
288 stars 188 forks source link

Interop with the Microsoft Graph SDK - DelegateAuthenticationProvider missing #1155

Open raclettierer opened 1 year ago

raclettierer commented 1 year ago

Category

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 commented 1 year ago

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

TashunkoWitko commented 1 year ago

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 commented 1 year ago

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

heinrich-ulbricht commented 6 months ago

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?