Token vide avec AuthIdentifie pour l'api Microsoft Graph
Bonjour,
J'ai récemment essayer d'utiliser L’API Graph de Microsoft. Pour le moment je n'arrive pas à récupérer le AuthToken que devrais renvoyer AuthIdentifie.
Je me suis servie de l'exemple de la documentation : https://doc.pcsoft.fr/?1000022219&la...ion=xxF250090f
Voici mon code, lorsque je l’exécute cela me redirige bien vers le pop-up de connexion puis je suis bien redirigé vers localhost:9000 avec le message sur la page "Vous pouvez maintenant fermer votre navigateur." mais toujours rien dans mon AuthToken.
Trace affiche seulement Valide a Faux
Rps serveur = | Valeur = | Valide = 0
Merci d'avance pour l'aide
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
// Paramètre de l'application
OAuth2Params est un OAuth2Paramètres
//ID de l'application
OAuth2Params..ClientID = sClientId
//SecretID
OAuth2Params..ClientSecret = sClientSecret
OAuth2Params..AuthURL = "https://login.microsoftonline.com/"+sTenantId+"/oauth2/v2.0/authorize"
OAuth2Params..TokenURL = "https://login.microsoftonline.com/"+sTenantId+"/oauth2/v2.0/token"
OAuth2Params..Scope = "Sites.ReadWrite.All"
//OAuth2Params..Scope = "Calendars.Read.Shared"
//OAuth2Params..Scope = "Mails.Read.All"
OAuth2Params.URLRedirection = "http://localhost:9000/"
// Demande d'authentification : ouvre la fenêtre de login
MonToken est un AuthToken = AuthIdentifie(OAuth2Params)
Trace("Rps serveur = " + MonToken.RéponseServeur + " | Valeur = " + MonToken.Valeur + " | Valide = " + MonToken.Valide)
IF MonToken <> Null THEN
IF ErrorOccurred THEN
Error("Une erreur s'est produite lors de la tentative de connexion a SharePoint " + CR + ErrorInfo())
RESULT False
END
RESULT True
END |
Requête POST infini API Graph
Alors j'ai bien réussi à me connecter et à obtenir le token. Avec Postman j'ai bien réussi à utiliser les endpoints de l'API pour créer, modifier les rendez-vous d'un calendrier mais lorsque je veux le faire sur Windev l'envoie de ma requête bloque à l'infini. Mais aucune erreur m'est retournée.
Le problème vient très certainement du contenu du body JSON que j'envoie mais je n'arrive pas à voir ce qui pose problème avec ce dernier.
Ma partie Windev
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| clOAuthMicrosoft est une OAuthOffice365
clOAuthMicrosoft.Connect()
ReqPostGraph est une httpRequest
ResPostGrap est une httpResponse
Contenu est un JSON
// Param de ma Req
ReqPostGraph..URL = "https://graph.microsoft.com/v1.0/me/calendars/idCalendrier/events"
ReqPostGraph..Méthode = httpPost
ReqPostGraph..AuthToken = clOAuthMicrosoft.m_TokenSession
ReqPostGraph..ContentType = "application/json"
ReqPostGraph..Entête["Authorization"] = "Bearer "+clOAuthMicrosoft.m_TokenSession.Valeur
vContenuVariant est un Variant
ReqPostGraph..DuréeNonRéponse = 10000
// Variant de mon body
vContenuVariant.subject = "Test Graph"
vContenuVariant.body.contentType = "HTML"
vContenuVariant.body.content = "Test corps depuis Windev"
vContenuVariant.start.dateTime = "2024-04-20T13:00:00"
vContenuVariant.start.timeZone = "Europe/Paris"
vContenuVariant.end.dateTime = "2024-04-20T14:00:00"
vContenuVariant.end.timeZone = "Europe/Paris"
vContenuVariant.location.displayName = "sTestLieu"
Contenu = VariantVersJSON(vContenuVariant)
ReqPostGraph..Contenu = Contenu
// Boucle infini
ResPostGrap = HTTPEnvoie(ReqPostGraph)
Trace(ResPostGrap.CodeEtat, ResPostGrap.Contenu) |
J'ai extrait le JSON que je créais et je l'ai tester sur Postman tout fonctionne bien
Code:
{ "subject":"Test Graph", "body":{ "contentType":"HTML", "content":"Test crops depuis Windev" }, "start":{ "dateTime":"2024-04-20T13:00:00", "timeZone":"Europe/Paris" }, "end":{ "dateTime":"2024-04-20T14:00:00", "timeZone":"Europe/Paris" }, "location":{ "displayName":"sTestLieu" } }