Messaging: First working version of OAuth2
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Messaging.Mail.MailSession
|
||||
Imports Limilabs.Client.IMAP
|
||||
Imports Microsoft.Identity.Client
|
||||
|
||||
Public Class OAuth2
|
||||
@@ -27,21 +28,25 @@ Public Class OAuth2
|
||||
ClientSecret = pClientSecret
|
||||
End Sub
|
||||
|
||||
Private Async Function GetAccessToken(pSession As SessionInfo) As Task(Of String)
|
||||
Public Function GetAccessToken() As String
|
||||
Logger.Debug("Fetching Access Token..")
|
||||
|
||||
Try
|
||||
' Create the application, which is defined in
|
||||
' Microsoft.Identity.Client
|
||||
Dim oApp = ConfidentialClientApplicationBuilder.
|
||||
Create(pSession.ClientId).
|
||||
WithTenantId(pSession.TenantId).
|
||||
WithClientSecret(pSession.ClientSecret).
|
||||
Build()
|
||||
Create(ClientId).
|
||||
WithTenantId(TenantId).
|
||||
WithClientSecret(ClientSecret).
|
||||
Build()
|
||||
|
||||
' Request an access token
|
||||
Dim oScopes = New List(Of String) From {O365_SCOPE}
|
||||
Dim oResult = Await oApp.
|
||||
Dim oResult = oApp.
|
||||
AcquireTokenForClient(oScopes).
|
||||
ExecuteAsync()
|
||||
ExecuteAsync().Result
|
||||
|
||||
Logger.Debug("Access Token fetched.")
|
||||
|
||||
Return oResult.AccessToken
|
||||
Catch ex As Exception
|
||||
|
||||
Reference in New Issue
Block a user