FOROS PROFESIONALES
WINDEV
,
WEBDEV
y
WINDEV Mobile
Inicio
|
Mensajes recientes
|
Conéctese...
|
Desconectar
|
Español
Inicio
→
WINDEV 2024
→
AuthIdentify - O365Graph
AuthIdentify - O365Graph
Iniciado por Ledoux D, 29,jul. 2021 10:46 - No hay respuesta
Conéctese…
Ledoux D
#1
Publicado el 29,julio 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.
Informar
0
0
→ Volver a WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (versiones precedentes)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Búsqueda Tipo
Sólo temas
Todos los mensajes
Periodo Buscar
Cualquier fecha
Última hora
Última 24 horas
Última semana
Último mes
Último año
Cancelar
Vista previa del mensaje
Añadiendo una imagen
Importar una imagen desde una URL
Enviar una imagen desde un archivo de su disco
Arrastrar un archivo o click en "Examinar..."
o
Cancelar
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Texto