We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ITokenProvider in vb.net class

Hi guys

i am trying to implement the sample code for getting an access token for o365.
the samples are all in c# and my project is vb.net.
normally, this is not an issue, however, i am having trouble trying to inherit the ITokenProvider object.
i am getting the error: classes can inherit only from other classes
do you have any suggestions or samples for this in vb?


I suggest you to please visit the following thread to serve the purpose. You need to port the C# based example code to VB .NET using standard tools even.

Hi there

when i take this code and covert to VB, i get an error with how Inherits Aspose.Email.Clients.ITokenProvider is referenced. This works in C# but not VB.
Any suggestions?


Can you please share the sample Visual Studio project that you have ported and has issue on your end.

Public Class AzureTokenProvider
Inherits Aspose.Email.Clients.ITokenProvider

Private ReadOnly _tenantId As String
Private ReadOnly _clientId As String
Private ReadOnly _clientSecret As String
Private ReadOnly _scopes As String()
Private ReadOnly _tokenSyncObj As Object = New Object()
Private _token As Aspose.Email.Clients.OAuthToken

Public Sub New(ByVal tenant As String, ByVal clientId As String, ByVal clientSecret As String, ByVal scopes As String())
    _tenantId = tenant
    _clientId = clientId
    _clientSecret = clientSecret
    _scopes = scopes
End Sub

Public Overridable Function GetAccessToken(ByVal ignoreExistingToken As Boolean) As Aspose.Email.Clients.OAuthToken
    SyncLock _tokenSyncObj
        If _token IsNot Nothing AndAlso Not Me._token.Expired AndAlso Not ignoreExistingToken Then Return _token
        _token = GetNewAccessToken()
        Return _token
    End SyncLock
End Function

Public Function GetAccessToken() As Aspose.Email.Clients.OAuthToken
    Return GetAccessToken(False)
End Function

Private Function GetNewAccessToken() As Aspose.Email.Clients.OAuthToken
    Dim app = ConfidentialClientApplicationBuilder.Create(_clientId).WithAuthority(AzureCloudInstance.AzurePublic, _tenantId).WithClientSecret(_clientSecret).Build()
    Dim authResultTask = app.AcquireTokenForClient(_scopes).ExecuteAsync()
    Dim authResult = authResultTask.Result
    Return New Aspose.Email.Clients.OAuthToken(authResult.AccessToken, Aspose.Email.Clients.TokenType.AccessToken, authResult.ExpiresOn.LocalDateTime)
End Function

Public Overridable Sub Dispose()
End Sub

End Class

the first line Inherits Aspose.Email.Clients.ITokenProvider is invalid


I can observe the issue while inheriting class. I have included the information in EMAILNET-39868 for further investigation and will share the feedback with you as soon as it will be fixed.


You may please need to implement the interface rather than using inherit. Please try “Implements”.

the implements solved the issue with the itokenprovider. thank you.
however, when i try to use the code AzureROPCTokenProvider referred to in the link above, there is a line:
Dim t As AzureTokenResponse
where is AzureTokenResponse? i cannot find any reference to this class.
i simply get an is not defined error message.
is there an imports i am missing?

found the class in another post.
one step closer, but not there yet.
now i am getting “not implemented” errors in ITokenProvider_GetAccessToken.
will post if i can figure out the cause.


It’s good to know things are moving ahead on your end.