PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 25 → Rest with autenticacao
Rest with autenticacao
Started by BOLLER, Mar., 05 2020 10:06 PM - 4 replies
Registered member
3,651 messages
Popularité : +175 (223 votes)
Posted on March, 05 2020 - 10:06 PM
Exemplo





Procedure _VérifieAuthentification(LOCAL bufDonnées is Buffer,LOCAL sUtilisateur is string,LOCAL sSignature is string)

// Sauve l'utilisateur
sUtilisateurRecu is string = sUtilisateur

// Flag iOS
biOS is boolean

// lit l'utilisateur
IF HReadSeekFirst(Utilisateur,Login,sUtilisateur) = False THEN
// On ne trouve pas l'utilisateur
RESULT ""
END

// Sauve la clé privée sur le disque temporairement
sEmplacementClePrivee is string = fDataDir() + [fSep] + GetGUID(guidRough) + ".pem"
IF fSaveBuffer(sEmplacementClePrivee ,Utilisateur.ClePrivee) = False THEN
RESULT "Impossible de sauver la clé"
END

// Décrypte le buffer de données avec la clé privée de l'utilisateur
sDecrypte is string = DecryptAsymmetric(HexaToBuffer(bufDonnées), sEmplacementClePrivee , "", cryptPaddingPKCS1)

// Si erreur, possible due à iOS qui encode pas comme il faut, on change l'encodage
IF sDecrypte ~~ "" THEN

// Conversion des données
bufOK is Buffer
FOR i = 1 _TO_ Length(bufDonnées)
IF Modulo(i,4) IN (0,3) THEN
// on ne prend pas
ELSE
// Copie dans un buffer correct
bufOK += bufDonnées[[i]]
END
END
bufDonnées = bufOK

// Récupère la chaine unicode
sDecrypte = DecryptAsymmetric(HexaToBuffer(bufDonnées), sEmplacementClePrivee , "", cryptPaddingPKCS1)

// encode l'utilisateur comme il faut
sEncodeUtilisateurOK is string
FOR i = 1 _TO_ Length(sUtilisateur)
// Copie dans un buffer correct
sEncodeUtilisateurOK += sUtilisateur[[i]] + sDecrypte[[2]]
END
sUtilisateur = sEncodeUtilisateurOK

// On est a priori en mode iOS
biOS = True
END

// Supprime la clé temporaire
fDelete(sEmplacementClePrivee )

// Vérifie la signature des données (avec le nom de l'utilisateur)
sSignatureCalculée is string = sDecrypte + sUtilisateur
sSignatureCalculée = BufferToHexa(HashString(HA_MD5_128,sSignatureCalculée))

// Il faut encoder comme il faut le message decrypté
IF biOS THEN

// Decode les données pour iOS
sDecrypteOK is string
FOR i = 1 _TO_ Length(sDecrypte)
IF Modulo(i,2) = 1 THEN
sDecrypteOK += sDecrypte[[i]]
END
END
sDecrypte = sDecrypteOK

END


// Vérifie la signature identique, si ce n'est pas le cas, c'est que les données ou l'utilisateur a été modifié
IF sSignatureCalculée = sSignature THEN
// Tout est ok
RESULT "Utilisateur : " + sUtilisateurRecu + CR + "Données : " + sDecrypte
END

// Pas la bonne signature, les données ont été modifiées
RESULT ""


Procedure TestSecurise()

// Vérification de l'utilisateur
sUtilisateurAVerifier is string = WebserviceReadHTTPHeader("Utilisateur") // <---------------- AQUI
sSignature is string = WebserviceReadHTTPHeader("Signature")
sInformations is string = _VérifieAuthentification(WebserviceParameter(paramBuffer),sUtilisateurAVerifier,sSignature)

IF sInformations = "" THEN
RESULT "Échec de l'authentification, aucune action ne sera réalisée."
ELSE
RESULT "Le message n'a pas été modifié, authentification réussie." + CR + "informations transmises au Webservice : " + CR + sInformations
END

// Appel ici du code métier


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Registered member
3,651 messages
Popularité : +175 (223 votes)
Posted on March, 05 2020 - 10:10 PM
https://help.windev.com/en-US/…

https://help.windev.com/en-US/…

https://help.windev.com/en-US/…

https://help.windev.com/en-US/…

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Registered member
3,651 messages
Popularité : +175 (223 votes)
Posted on March, 06 2020 - 12:40 PM
//É assim que lê o Header de uma requisição REST

Usuario is string = WebserviceReadHTTPHeader("User")
Senha is string = WebserviceReadHTTPHeader("Password")
...
Usa dai o usuario dentro DO codigo lendo da base se bate com os dados informados

OK


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Registered member
3,651 messages
Popularité : +175 (223 votes)
Posted on May, 20 2020 - 5:09 PM
ATENÇÃO

Write Header
https://help.windev.com/en-US/…
https://help.windev.com/en-US/?1000022788&name=WebserviceWriteHTTPHeader


Read Header
https://help.windev.com/en-US/…
https://help.windev.com/en-US/?1000022787&name=WebserviceReadHTTPHeader


A funcao read e a funcao write é ideia igual do ini

simples assim:

o write coloca no teu webservice antes de publicar

e o read quando for consumir o webservice

//----

The read function and the write function is the same idea as the start

that simple:

write puts on your webservice before publishing

and read when consuming webservice

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Registered member
3,651 messages
Popularité : +175 (223 votes)
Posted on July, 06 2021 - 7:48 PM
Passando para agradecer o @?Ricardo Cassolato Cliente Pgto? pela ajuda, estava precisando passar um JSON No body da requisição e me ajudou de imediato, meu muito obrigado!

JsonResponse is JSON = ""
sJsonBody is string = {"usuario":"[%variavel_usuario%]","senha":"[%variavel_senha%]"}
MyRequest is httpRequest
MyRequest..URL = "https://192.168.15.250/wsmobileautenticar.rule?sys=CIE"
MyRequest..Method = httpPost
MyRequest..Timeout = 180s
MyRequest..Content = sJsonBody
MyResponse is httpResponse = HTTPSend(MyRequest)
JsonResponse = MyResponse..Content