GraphClient doesn't work

I need a full sample to use GraphClient with dotNet, this documentation (How to use GraphClient for Microsoft Graph|Documentation) is not complete and it’s not updated.

Public Class AccessParameters_APP
Public Property TenantId As String
Public Property ClientId As String
Public Property ClientSecret As String
Public Property Scopes As String() = {“Sign in to Outlook”}
End Class

Public Class siscAccessToken365
Public Shared Async Function GetAccessToken_APP(ByVal accessParameters As Locale.AsposeComponent.AccessParameters_APP) As System.Threading.Tasks.Task(Of String)
Try
Dim cca = Microsoft.Identity.Client.ConfidentialClientApplicationBuilder.Create(accessParameters.ClientId).WithClientSecret(accessParameters.ClientSecret).WithTenantId(accessParameters.TenantId).Build()

        Dim result = Await cca.AcquireTokenForClient(accessParameters.Scopes).ExecuteAsync()

        Locale.AsposeComponent.AsposeManager.resTokenAuth = result

        Return result.AccessToken

    Catch ex As Exception

    End Try
End Function

End Class

’ LOGIN LIKE APP - SECRET Code
Dim mieiParam As New AccessParameters_APP
mieiParam.ClientId = “…”
mieiParam.ClientSecret = “…”
mieiParam.TenantId = “…”
Dim myScopes As String()
ReDim myScopes(0)
myScopes(0) = “Sign in to Outlook
mieiParam.Scopes = myScopes

        Call siscAccessToken365.GetAccessToken_APP(mieiParam)

        Do
            Application.DoEvents()
            System.Threading.Thread.Sleep(100)

            If IsNothing(resTokenAuth) Then
                ' wait
            Else
                If Trim(resTokenAuth.AccessToken) <> "" Then Exit Do
            End If
        Loop

I have token, but now?

Dim clientApp As Aspose.Email.Clients.Graph.IGraphClient = Aspose.Email.Clients.Graph.GraphClient.GetClient( ??

@Siscom

A ticket has been logged in our issue tracking system for your case as EMAILNET-40845 to update the documentation. We will inform you once there is an update available on it. We apologize for your inconvenience.

Hello, @Siscom

I have token, but now?
Dim clientApp As Aspose.Email.Clients.Graph.IGraphClient = Aspose.Email.Clients.Graph.GraphClient.GetClient( ??

A GetClient method requires an ITokenProvider implementation instance as the first parameter.
In its simplest form, the ITokenProvider implementation will be as follows:

public class GraphTokenProvider : ITokenProvider
{
    private readonly string? _token;
    
    public GraphTokenProvider(string token)
    {
        _token = token;
    }
    
    public void Dispose()
    {
        throw new NotImplementedException();
    }

    public OAuthToken GetAccessToken()
    {
        return GetAccessToken(false);
    }

    public OAuthToken GetAccessToken(bool ignoreExistingToken)
    {
        return new OAuthToken(_token);
    }
}

You maybe complicate the ITokenProvider implementation as you require, for example, implement the logic of getting a token internally.

Next, pass the created instance of ITokenProvider to the GetClient method:

var tokenProvider = new GraphTokenProvider(token);

using var client = GraphClient.GetClient(tokenProvider, tenantId);

Also, we have attached an example of a test app (GraphApp.zip (2.3 KB)) using GraphClient.

Thanks.