User bio
404 bio not found
Member since Oct 2, 2023
Replies:

Hi, 

I have the same problem.
I want to connect to office365 using OAuth2 and the IMAP protocol.

I was inspired by this post to use IMAP in IRIS : https://community.intersystems.com/post/implementing-imap-client-intersy...

I always have a system error when launching the command to connect in OAUT2

Do you know how to connect in OAUTH2 with IMAP in IRIS?

Here is the method : 

Method SendCommand(pCommand As %String = "") As %String

{

    Do ..Log("Dans BastideIMAPHelper :  SendCommand")

    Set currIO = $IO

    Set exception = ""

    Try {

        Set command = ""

        If (pCommand '= "") {

            Set tag = ..GetTag()

            Set command = tag_" "_pCommand

        }

        Do ..Log("Using device: "_..Device)

        Use ..Device

        If ($FIND(command, " AUTHENTICATE ") > 0) {

            // don't log passwords

         Set command = "AUTHENTICATE XOAUTH2 " _ authorizationHeader

            Do ..Log("Sending command 1: "_$P(command, " ", 1, 3)_" <password hidden>")

        }

     

        Write:(command '= "") command,!

       #; Set status = $zf(-1, command)

        Set ..CurrentCommand = pCommand

        Set ..CurrentTag = tag

        Do ..ReadResponse(.response)

    }

    Catch ex {

        Set exception = ex

        Do ..Log("Error in command execution: "_ex.DisplayString())

    }

    Use currIO

    Throw:$IsObject(exception) exception

    Return response

}

/// Description

Method ReadResponse(ByRef pResponse As %String) [ Internal ]

{

    Try {

    Set buffer = ""

    Set pResponse = ""

    Set tokensLine = ""

    While(1) {

        Read buffer:..Timeout

        Set readOK = $TEST

        Set pResponse = pResponse_buffer

        If (..CurrentCommand = "") Quit

        If (readOK) {

            // splits the current response by CRLF

            Set lines = $LISTFROMSTRING(buffer, $Char(13, 10))

            // if the whole response was retrieved, the line with the

            // tag of the command is the (n-1)-th, due the message

            // finishes with CRLF, so the n-th list element is ""

            Set ackLine = $LISTGET(lines, * - 1)

            // splits the lines by white space

            Set tokensLine = $LISTFROMSTRING(ackLine, " ")

            // if the whole message was retrieved, the first token has

            // the tag of the command

            Set tagToken = $LISTGET(tokensLine, 1)

            // check if the first token is the expeted tag, if so, the

            // whole message was retrieved and leave the loop

            If (tagToken = ..CurrentTag) Quit

        } Else {

            Quit

        }

    }

    }

    Catch ex {

        Set tSC=ex.AsStatus()

        Set exception = ex

        Do ..Log("Error in ReadResponse: "_ex.DisplayString())

    }

    // check if the whole message was retrieved and its status is OK

    Set ackToken = $LISTGET(tokensLine, 2)

    If (ackToken '= "OK") {

      Throw ##class(IMAPException).%New("IMAP error: "_$LISTTOSTRING(tokensLine, " "))

    }

}

Here is the command log 

command  : TAG1 AUTHENTICATE XOAUTH2 Bearer " AcccessToken value"

Here is error :

ERROR #5002: ObjectScript error: <WRITE>SendCommand+22

Thank you very much for your help 

Certifications & Credly badges:
Moussa has no Certifications & Credly badges yet.
Global Masters badges:
Followers:
Moussa has no followers yet.
Following:
Moussa has not followed anybody yet.