Skip to main content
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

Uniface 9: [SOLVED] Cosmos DB Emulator and Uniface

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

18 replies

Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

So you had you tried this: raw vskeyRaw string vskey vskeyRaw=$encode(“HMAC_SHA256″,”%%vshash”,”%%vsmaster”) vskey=$encode(“BASE64″,”%%vsKey”) I haven't digged into this now, but I found some testing I did some months ago, finding that SHA1 and HMAC_SHA256 works in Uniface, except for empty "" value. We tested somehow like this: variables raw tRaw string tBase64 endvariables debug ;tRaw = $encode("HMAC_SHA256", "f95fa8b05c6747ffff790d7c4444f6d8|POST|https://changedapi/changed/changed|1446723703|983fchanged71a8f9e|2jmj7l5rchangedK/YBwk=", "dj4qUsjchangedTvchangedM=") ;tBase64 = $encode("BASE64", tRaw) tRaw="" tRaw = $encode("SHA1", tRaw) tBase64 = $encode("BASE64", tRaw) perhaps you can learn something from this. Regards RogerW.


Author: rogerw (roger.wallin@abilita.fi)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

So, application/json wasn't fixed (from what I understand) until 9.7.2. (https://unifaceinfo.com/forum/uniface9/restful-service-in-uniface/) What does the IIS error logs say? Knut


Author: Knut (knut.dybendahl@gmail.com)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

9.7.1 and also tested with 9.7.3


Author: tommyb42 (tommy.balkis@gmail.com)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

What's the Uniface version in question?


Author: Knut (knut.dybendahl@gmail.com)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

Hi Roger ,  The Problem actualy it is on the authorization token, by the way it is produced from uniface and how it's read from the cosmos db.


Author: tommyb42 (tommy.balkis@gmail.com)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

I've done something similar, using a somehow different syntax for the sending. But that's probably the same functionality. ; Call the UHTTP.SEND operation vUHTTP->SET_FLAGS(8) ;Send headers with all methods. By default, headers are sent only on the POST and PUT methods. vStatus = vUHTTP->SEND(vURI, "GET", "", "", vHeaders, vContent, vResponse) Can't see any other way than comparing what you send from VS to what you send from Uniface. Regards RogerW.


Author: rogerw (roger.wallin@abilita.fi)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

Yes Iain , i ve tried  same error responce.Cry


Author: tommyb42 (tommy.balkis@gmail.com)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

I've no major clue, but $encode returns a raw value. Have you tried making the vskey variable a raw datatype?


Author: Iain Sharp (i.sharp@pcisystems.co.uk)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

tommyb42 said By Changing the last Line of Daniels Code to vOutput = $encode("URL", $concat("type=", vKeyType, "&ver=", vTokenVersion, $concat("&sig=", vSignature))) Finaly I Get The Http 200 Ok. Thanks all of you for your help.   

Thanks for your feedback. Good to hear that you've got it working now. I'm not sure what happened with my code example, but it seems that the editor converted the "&" to "&". I've corrected this now.


Author: diseli (daniel.iseli@uniface.com)
Jan Cees Boogaard
Rocketeer
Nov 19, 2018 11:39 AM UTC

[SOLVED] Cosmos DB Emulator and Uniface

Author: tommy.balkis@gmail.com (tommyb42)

Hi all ,  I am trying to develop a Restfull Api call with Uniface  to microsoft Cosmos Db emulator. They have a complex  Authorization token which i construct it  according to microsft 's instructions. I'm always getting an error from the token validation from server but i cannot find a possible reason. I make the same call from visual studio with .Net Sdk and it works fine  Please find below the uniface code for the http call  ;-------------------------------------------------------------------- Variables String vsUsername String vsPassword String vsUrl String vsHttpHeader String vsHttpContent String vsResponse String vsmaster numeric vnHour String vsHash String vsVerb String vsKey String vsDate String vsResType String vsResLinks EndVariables vnHour =$datim[H]-3 vsmaster="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" vsmaster =$decode("BASE64", "%%vsmaster") vsVerb="GET" vsResType="dbs" vsResLinks ="" vsDate ="%%$datim[Aaa]%%%,%%% %%$datim[d]%%% %%$datim[Mmm]%%% %%$datim[y]%%% %%FixSize("%%vnHour ",2,"0",1)%%%:%%FixSize("%%$datim[n]",2,"0",1)%%%:%%FixSize("%%$datim[s]",2,"0",1)%%% GMT" vsHash ="%%$Lowercase(vsVerb)%%^%%$lowercase(vsResType)%%^%%vsResLinks%%^%%$Lowercase(vsDate)%%^%%% %%^" vskey=$encode("HMAC_SHA256","%%vshash","%%vsmaster") vskey=$encode("BASE64","%%vsKey") vskey=$encode("URL","type=master&ver=1.0&sig=%%vskey") NewInstance "UHTTP" , "CosmosDb" Activate "CosmosDb".Set_Flags(10) vsResponse = "" vsUrl = "https://localhost:8081/dbs" putitem/id/case vsHttpHeader, "Authorization","%%vsKey" putitem/id/case vsHttpHeader, "x-ms-date","%%vsDate" putitem/id/case vsHttpHeader,"Content-Type", "application/json;charset=UTF-8" putitem/id/case vsHttpHeader, "x-ms-version","2017-02-22" Activate "CosmosDb".send(vsUrl, %\\ "GET", %\\ vsUsername, %\\ vsPassword , %\\ vsHttpHeader, %\\ vsHttpContent, %\\ vsResponse) If ($Status !=200) message/info "%%vsHttpContent" Endif If ($Status=200 ) message/info "%%vsResponse" Endif ;-------------------------------------------------------------------- I am using uniface 9.7.1 and i also run it from uniface 9.7.3 You can download the emulator from here : https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator and  the Api Referece from here :https://docs.microsoft.com/en-us/rest/api/cosmos-db/access-control-on-cosmosdb-resources   I would appreciate every help to make it  work  from uniface.   Regards Thomas

By Changing the last Line of Daniels Code to vOutput = $encode("URL", $concat("type=", vKeyType, "&ver=", vTokenVersion, $concat("&sig=", vSignature))) Finaly I Get The Http 200 Ok. Thanks all of you for your help. 


Author: tommyb42 (tommy.balkis@gmail.com)