Quantcast
Channel: Chilkat Forum - latest questions
Viewing all articles
Browse latest Browse all 1061

Using my own OAuth2 token with mailman?

$
0
0

I have looked at the documentation about GMail and I quote:

GMail: If sending via smtp.gmail.com, then send with OAuth2 authentication if possible. Otherwise you will need to change your GMail account settings to allow for sending by less secure apps. See the links below.

I have reviewed the sample code that uses your HTTP library for the task in hand. However, I am already having to fund the Email library and at the moment it is beyond my circumstances to purchase an additional library.

Now, I have already written my own VB.NET utility to communicate with a GMail Calendar and I do the authentication like this:

Private Function DoAuthentication(ByRef rStrToken As String, ByRef rParameters As OAuth2Parameters) As Boolean
    Dim credential As UserCredential
    Dim Secrets = New ClientSecrets() With {
        .ClientId = m_strClientID,
        .ClientSecret = m_strClientSecret
    }
    'm_Scopes.Add(CalendarService.Scope.Calendar)
    m_Scopes.Add("https://www.googleapis.com/auth/calendar https://www.google.com/m8/feeds/")

    Try
        credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, m_Scopes,
                                                                 "user", CancellationToken.None,
                                                                 New FileDataStore("PublicTalkSoftware.Calendar.Application")).Result()

        ' Create the calendar service using an initializer instance
        Dim initializer As New BaseClientService.Initializer() With {
            .HttpClientInitializer = credential,
            .ApplicationName = "GoogleCalIF"
        }
        m_Service = New CalendarService(initializer)

        rStrToken = credential.Token.AccessToken.ToString()
        rParameters.AccessToken = credential.Token.AccessToken
        rParameters.RefreshToken = credential.Token.RefreshToken
    Catch ex As Exception
        ' We encountered some kind of problem, perhaps they have not yet authenticated?
        ' Can we isolate that as the exception?

        Return False
    End Try

    Return True
End Function

So what I am asking is if they is a similar way that I can do the authentication bit myself so that I can just pass the token needed into the mailman object?

Thanks.


Viewing all articles
Browse latest Browse all 1061

Trending Articles