oAuth2 - Azure question

Posted by goo on 01-Oct-2019 13:59

https://docs.microsoft.com/en-us/azure/active-directory/develop/v1-protocols-oauth-code

I have been doing a server to server communication using the code under. But now I have been told to use the above link for a server to server connection, but after reading it, I get an impression that I will be asked for username and password. Is it possible to use it for server to server communication? 

METHOD PUBLIC VOID LoginByClient(ipUri AS CHARACTER, ipClientId AS CHARACTER, ipClientSecret AS CHARACTER):

ASSIGN
APIUri = ipUri
APIClientId = ipClientId
APIClientSecret = ipClientSecret
.

oUri = NEW System.Uri(APIUri).
System.Threading.Thread:Sleep(1000).

System.Net.ServicePointManager:SecurityProtocol = System.Net.SecurityProtocolType:Tls12.

oAuthParam = Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationParameters:CreateFromResourceUrlAsync(oUri).
System.Threading.Thread:Sleep(2000).

oAuthContext = NEW Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(oAuthParam:Result:Authority).
System.Threading.Thread:Sleep(2000).

oClientCredential = NEW Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(APIClientId,APIClientSecret).

System.Threading.Thread:Sleep(100).
Token = oAuthContext:AcquireToken(oAuthParam:Result:Resource,oClientCredential):AccessToken.


CATCH eAnySystem AS System.AggregateException :
MESSAGE 'FEIL:' eAnySystem:GetMessage(1) view-as alert-box.
END CATCH.

CATCH eAny AS Progress.Lang.Error :
MESSAGE 'FEIL:' eAny:GetMessage(1)
VIEW-AS ALERT-BOX.
StatusMessage = eAny:GetMessage(1).
JBoxLogHandling:addLog('ERROR','Feilet ved henting av Token:' + eAny:GetMessage(1) + ' i ' + program-name(1)).
END CATCH.

END METHOD.

All Replies

Posted by goo on 01-Oct-2019 14:20
This thread is closed