User bio
404 bio not found
Member since Feb 28, 2018
Posts:
Replies:
Samantha Forish · Jul 10, 2024 go to post

Yes, we built GetAuthorizationToken method ourselves so you can compose the request however you need.

Basically, in order to get your token, you are just making another REST request to their authorization endpoint.

Example:

Method GetAuthorizationToken() As%Status
{
//Authenticate with Systemset tHttpResponse=##class(%Net.HttpResponse).%New()
    set tHttpRequest = ##class(%Net.HttpRequest).%New()
    set tHttpRequest.ContentType="application/x-www-form-urlencoded"//Get username and pwd out of Credential storeset objCred = ##class(Ens.Config.Credentials).%OpenId(..Adapter.Credentials)
//Insert the username and pwd (in your case may be "email" instead of "username")do tHttpRequest.InsertFormData("username",objCred.Username)
    do tHttpRequest.InsertFormData("password",objCred.Password)
    //add any other things the request may need//send auth requestset tURL=..AuthURLset tSC = ..Adapter.SendFormDataArray(.tHttpResponse,"POST",tHttpRequest,"","",tURL)
    
    //Get response, were our credentials accepted?set tStatusCode = tHttpResponse.StatusCode
    $$$TRACE("Authorization Status Code [" _ tStatusCode _ "]")
    if tStatusCode = 200 {
        set..tToken=tHttpResponse.access_token
        Return$$$OK
    } else {
    Quit$$$ERROR("5001", "tStatusCode - can't auth with System")
        }
    }
}
Samantha Forish · Jul 8, 2024 go to post

What we have typically built into our code is that the OnInit() will just call a separate ..GetAuthorizationToken method where the authorization code is stored.

Then in our GET methods (or whatever API endpoint you are consuming), if we receive a '401 Unauthorized' HTTP Status Response, at that point we will call out to the ..GetAuthorizationToken method. We will get a fresh token, and then continue down the GET method.

There is no need to get a fresh token every time. If we are getting 200 OK responses back, the token must be valid. It should be that when you get a 401 status response, you can capture that into an "if" statement and just call out to your GetAuthorizationToken method at that point.

Samantha Forish · Jun 16, 2023 go to post

I found this is just an issue with the UI - I may try extending the XML Adaptor on my message class to see if that will help display the field. But I am able to access my field and was able to test it was available with the following in studio console:

set msg=##class(AH.AHLIB.Custom.Athena.Message.GetEventsSubscribedResponse).%OpenId(<messageIDfromtester>)

set test=""

set tsC=msg.%JSONExportToString(.test)

w test

Certifications & Credly badges:
Samantha has no Certifications & Credly badges yet.
Followers:
Following:
Samantha has not followed anybody yet.