FORUMS PROFESSIONNELS
WINDEV
,
WEBDEV
et
WINDEV Mobile
Accueil
|
Messages récents
|
Connexion
|
Déconnexion
|
Français
Accueil
→
WINDEV 2024
→
AuthIdentify - O365Graph
AuthIdentify - O365Graph
Débuté par Ledoux D, 29 juil. 2021 10:46 - Aucune réponse
Connectez-vous…
Ledoux D
#1
Posté le 29 juillet 2021 - 10:46
Hello all,
I'm struggling with OAuth2 and Graph.
It's just testing at this point to find a workable situation for our company, so ignore that fact that mailing might be easier in another way.
What I'm trying to achieve at this point its just a mail that needs to be send via the application through graph.
I have registered the application successfully and correctly on the Azure platform also successfully tested via Postman.
First thing I tested was the standard WINDEV teaches with AuthIdentify.
The code beneath works to send the mail.
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
<
Description
=
"mail"
>
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
But I have an issue with this method.
Each time the AuthIdentify() is called, a browser opens to tell me it successfully got the token and I can "close the browser now".
Since there will be a lot of calls during a day that would mean that I would get spammed with pages opening on a pc/server side.
Is there any way in stopping that webpage from opening?
I also tried the following code.
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
)
v
Var
is
Variant
=
JSONToVariant
(
HTTPres.Content
)
This successfully gets the Bearer token but then I seem to be unable to use it to execute the request to mail with that token.
I tried making a AuthToken with the HTTPres response.
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
is AuthToken
(
MyTokenParam
,
VariantToJSON
(
v
Var
)
)
But that doesn't seem to be working since no mail is send.
I also tried to not use an AuthToken and tried a normal http request with header option but that also doesn't seem to be working.
req
is httpRequest
req.Method
=
httpPost
req.URL
=
"https://graph.microsoft.com/v1.0/users/davy.ledoux@mail.be/sendMail"
req.Header
[
"Authorization"
]
=
"Bearer "
+
v
Var.access_token
// Authentication token
//CreateMail
req.ContentType
=
"application/json"
mailJson
is JSON
<
Description
=
"mail"
>
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
)
Am I doing something wrong here or is what I'm trying to do impossible without AuthIdentify() and hence opening a browser page?
Thx for the help.
Kind Regards,
Davy.
Signaler
0
0
→ Revenir à WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (précédentes versions)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Type de recherche
Uniquement les sujets
Tous les messages
Période de recherche
Date indifférente
Moins d'une heure
Moins de 24 heures
Moins d'une semaine
Moins d'un mois
Moins d'un an
Annuler
Aperçu de votre message
Ajouter une image
Importer une image depuis une URL
Envoyer une image depuis un fichier de votre disque
Déposez ici un fichier ou cliquez sur "Parcourir..."
ou
Annuler
0%
WLangage
SQL
XML, HTML
JAVA, Javascript
Texte