PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV (précédentes versions) → [WD25] MS Graph - OAuthIdentify
[WD25] MS Graph - OAuthIdentify
Débuté par Ledoux D, 06 aoû. 2021 09:15 - Aucune réponse
Posté le 06 août 2021 - 09:15
Bonjour,

Tout d'abord, excuse-moi pour mon francais mauvais.

Allors, j'ai une problème avec OAuthIdentify.
Quand j'uttilise cette function, une fenêtre est ouvré chaque fois.

MyToken is AuthToken
MyTokenParam is OAuth2Parameters

MyTokenParam.ClientID = clientID
MyTokenParam.ClientSecret = clientSecret MyTokenParam.AuthURL = "https://login.microsoftonline.com/(tennant)/oauth2/v2.0/authorize"
MyTokenParam.TokenURL = "https://login.microsoftonline.com/(tennant)/oauth2/v2.0/token"
MyTokenParam.Scope = "https://graph.microsoft.com/.default"
MyTokenParam.AdditionalParameters = "grant_type=client_credentials"

MyToken = AuthIdentify(MyTokenParam)

IF MyToken <> Null THEN
IF ErrorOccurred THEN
Error(ErrorInfo())
ELSE
req is httpRequest
req.Method = httpPost
req.URL = "https://graph.microsoft.com/v1.0/users/davy.ledoux@mail.be/sendMail"
req.AuthToken = MyToken

req.ContentType = "application/json"
mailJson is JSON
mailJson.message.body.content = "Deze mail is verzonden met Graph, hopelijk komt hij mooi terecht."
mailJson.message.body.contentType = "Text"
mailJson.message.toRecipients[1].emailAddress.address = "davy.ledoux@mail.be"
mailJson.message.subject = "Graph Test"
req.Content = mailJson

HTTPresponse is httpResponse = HTTPSend(req)
END
END


Ce code marche parfaitment à l'exception de la fenêtre de confirmation.
Est-ce que c'est possible d'utilisez OAuthIdentify sans ouvert une fenêtre pour confirmez que le connection est créer avec succès?


Pour éviter ce problème, j'ai essayé d'utiliser un httpRequest sans le OAuthIdentify.
Mais quand je fais ca, je ne réussi pas d'executé le requête avec le Bearer-Token.

reqToken is httpRequest
reqToken.Method = httpPost
reqToken.URL = "https://login.microsoftonline.com/{tennant}/oauth2/v2.0/token"
reqToken.Content = "client_id={clientid}&scope=https://graph.microsoft.com/.default&client_secret={secret}&grant_type=client_credentials"
HTTPres is httpResponse = HTTPSend(reqToken)
vVar is Variant = JSONToVariant(HTTPres.Content)

req is httpRequest
req.Method = httpPost
req.URL = "https://graph.microsoft.com/v1.0/users/davy.ledoux@mail.be/sendMail"
req.Header["Authorization"] = "Bearer " + vVar.access_token // Authentication token

//CreateMail
req.ContentType = "application/json"
mailJson is JSON
mailJson.message.body.content = "Deze mail is verzonden met Graph, hopelijk komt hij mooi terecht."
mailJson.message.body.contentType = "Text"
mailJson.message.toRecipients[1].emailAddress.address = "davy.ledoux@mail.be"
mailJson.message.subject = "Graph Test"
req.Content = mailJson

HTTPresponse is httpResponse = HTTPSend(req)


Ce code au dessus obtient le token avec succès, mais n'execute pas le httpRequest "sendmail".
Est-ce que je manque quelque chose ou c'est pas passible de faire ce que je veux sans le OauthIdentify.

Merci on avance pour l'aide.

B-a-v,
Davy