Home

Graph API V2: Get the authorization code via VB

%3CLINGO-SUB%20id%3D%22lingo-sub-690534%22%20slang%3D%22en-US%22%3EGraph%20API%20V2%3A%20Get%20the%20authorization%20code%20via%20VB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-690534%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20using%20the%20Graph%20api%20(still%20testing)%20to%20access%20outlook%20and%20I%20want%20to%20let%20it%20run%20in%20the%20backend%20with%20VB.%20How%20can%20i%20get%20the%20authorization%20code%20with%20VB%3F%20In%20my%20testing%20scenario%20it%20works%20fine%2C%20if%20i%20request%20the%20token%20with%20VB%20(2nd%20Endpoint%20in%20V2).%20But%20this%20only%20works%20fine%20with%20the%20authorization%20code%20that%20I%20requested%20before%20with%20my%20browser%20(1st%20Endpoint%20V2%2C%20url%3A%20%3CFONT%3E%3CA%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ehttps%3A%2F%2Flogin.microsoftonline.com%2FTENANT%2Foauth2%2Fv2.0%2Fauthorize%3Fclient_id%3DCLIENTID%26amp%3Bresponse_type%3D...%3C%2FA%3E%3C%2FFONT%3E)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20does%20it%20work%20to%20get%20the%20code%20in%20the%20backend%3F%20I%20have%20tryed%20something%20like%20this%2C%20but%20the%20authorization%20fails%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EstrURL%20%3D%26nbsp%3B%3CFONT%3E%3CA%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ehttps%3A%2F%2Flogin.microsoftonline.com%2FTENANT%2Foauth2%2Fv2.0%2Fauthorize%3Fclient_id%3DCLIENTID%26amp%3Bresponse_type%3D...%3C%2FA%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EstrUser%3D%20%22user%40example.com%22%3C%2FP%3E%3CP%3EstrPassword%3D%20%22XXXX%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%26nbsp%3B%3CFONT%3EDim%20objHTTP%20'%20As%20MSXML.XMLHTTPRequest%3CBR%20%2F%3E%26nbsp%3BIf%20Len(strURL)%20Then%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B'%26nbsp%3BDim%20base64%20As%20New%20Base64()%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3BSet%20objHTTP%20%3D%20CreateObject(%22MSXML2.ServerXMLHTTP%22)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3BobjHTTP.setRequestHeader%20%22Authorization%22%2C%20%22Basic%20%22%20%2B%20base64.encode(strUser%20%2B%20%22%3A%22%20%2B%20strPassword)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3BobjHTTP.setRequestHeader%20%22Host%22%2C%20%22%3CA%20href%3D%22https%3A%2F%2Flogin.microsoftonline.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Flogin.microsoftonline.com%3C%2FA%3E%22%3C%2FFONT%3E%3CFONT%3E%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3BobjHTTP.open%20%22GET%22%2C%20strURL%2C%20False%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%3E%26nbsp%3B%26nbsp%3BobjHTTP.send%20(strPOSTString)%20'Get%20it.%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3BstrReturn%20%3D%20objHTTP.responseText%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3BEnd%20If%3CBR%20%2F%3E%26nbsp%3BSet%20objHTTP%20%3D%20Nothing%3CBR%20%2F%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%3EWho%20can%20help%20me%20to%20get%20the%20code%20with%20VB%3F%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CFONT%3EThanks!%3C%2FFONT%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
BerndST
Regular Visitor

Hello,

 

I am using the Graph api (still testing) to access outlook and I want to let it run in the backend with VB. How can i get the authorization code with VB? In my testing scenario it works fine, if i request the token with VB (2nd Endpoint in V2). But this only works fine with the authorization code that I requested before with my browser (1st Endpoint V2, url: https://login.microsoftonline.com/TENANT/oauth2/v2.0/authorize?client_id=CLIENTID&response_type=...)

 

How does it work to get the code in the backend? I have tryed something like this, but the authorization fails:

 

strURL = https://login.microsoftonline.com/TENANT/oauth2/v2.0/authorize?client_id=CLIENTID&response_type=...

 

strUser= "user@example.com"

strPassword= "XXXX"

 

 Dim objHTTP ' As MSXML.XMLHTTPRequest
 If Len(strURL) Then
  ' Dim base64 As New Base64()
  Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
  objHTTP.setRequestHeader "Authorization", "Basic " + base64.encode(strUser + ":" + strPassword)
  objHTTP.setRequestHeader "Host", "https://login.microsoftonline.com"

  
  objHTTP.open "GET", strURL, False
  objHTTP.send (strPOSTString) 'Get it.
  strReturn = objHTTP.responseText
  
 End If
 Set objHTTP = Nothing
 
Who can help me to get the code with VB?
 
Thanks!
Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies