Messaging: First working version of OAuth2

This commit is contained in:
Jonathan Jenne
2023-09-06 10:24:46 +02:00
parent 6f33261101
commit e8974376c5
4 changed files with 59 additions and 17 deletions

View File

@@ -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