Connecting rest api to C#
RéponduHow to use x-rainbow-app-auth parameter in C#?
I've tried it but I'm stuck on sha256.
-
Commentaire officiel
Hi Mahajir,
In order to user an application id in production platform, you have to deploy it before.
Regards
Vincent
Actions pour les commentaires -
Hi Mahajir,
thex-rainbow-app-auth is algorithm:
Basic <base64encode(appId:sha256(appSecretuserPassword))>
appSecret + userPassword -> no space
+ sha256
+ appId + ':' + result of sha256(xxx)
+ base64encode
could you try and compare you results using https://www.xorbin.com/tools/sha256-hash-calculator and https://www.base64encode.org/
Thank you
Regards
Vincent
-
thanks for your answer. now, i can handle it, but I have another problem.
when I try to log in using x-rainbow-app-auth with the url https://openrainbow.com/api/rainbow/authentication/v1.0/login, I don't get anything including an error message and the result is like the image below .
but when I remove the x-rainbow-app-auth parameter and use the URL https://sandbox.openrainbow.com/api/rainbow/authentication/v1.0/login, it works and I get the data.this is my script, maybe you can help me
this is the result of using x-rainbow-app-auth parameter and url openrainbow
and this the result when i remove x-rainbow-app-auth parameter and using sandbox.openrainbow.com
-
Hi Mahajir,
Are you using the right sha256 algorithm ?
The following part of code can help you.
Regards
Vincent
---
using System;
using System.Text;
using System.Security.Cryptography;
using IO.Swagger.Api;
using IO.Swagger.Model;
namespace auth
{
class Program
{
private static string CalculateHashedPassword(string text)
{
var crypt = new SHA256Managed();
string hash = String.Empty;
byte[] crypto = crypt.ComputeHash(Encoding.ASCII.GetBytes(text));
foreach (byte theByte in crypto)
{
hash += theByte.ToString("x2");
}
return hash;
}
static void Main(string[] args)
{
String authHeader = Convert.ToBase64String(Encoding.ASCII.GetBytes(loginEmail + ":" + password));
String hash = Program.CalculateHashedPassword(appSECRET + password);
String appAuthHeader = Convert.ToBase64String(Encoding.ASCII.GetBytes(appID + ":" + hash));
AuthenticationApi authenticationApi = new AuthenticationApi("https://openrainbow.com");
GetBasicLoginSuccess loginSuccess = authenticationApi.GetBasicLogin("Basic " + authHeader, "Basic " + appAuthHeader, "csharp", "0.1", "application/json")
}
}
} -
Hi Mahajir,
The appID you are using on the sandbox (https://sandbox.openrainbow.com/api/rainbow/authentication/v1.0/login), won't work on the production:
https://openrainbow.com/api/rainbow/authentication/v1.0/login
The HOWTO is the following:
- develop on the sandbox,
- then create an appID/Secret on the production,
- add a payment method,
- change your app from sandbox to production (don't forget to change also the appID)
- ask for your appID to be deployed on production
- *enjoy*
Best regards,
Pascal -
Warning: sandbox and production are two different server.
Nothing is shared: users and appID are different.On the sandbox, with https://sandbox.openrainbow.com/api/rainbow/authentication/v1.0/login does it work with the x-rainbow-app-auth built by the script ?
-
when URL_LOGIN is a sandbox and I don't use x-rainbow-app-auth, it works.
but when URL_LOGIN is a sandbox and uses x-rainbow-app-auth, it doesn't work with error message.
and when URL_LOGIN is production and uses x-rainbow-app-auth, it doesn't work without error message.
and at line 116 the script is "Debug.Log (www.downloadHandler.text)", that means it will display the results of the UnityWebRequest.Get (URL_LOGIN) as we request. the result should be {"token": ".....................", "loggedInUser": {............. ....}}. but I don't get results like that.
-
Ok.
Did you use/test as asked Vincent the "CalculateHashedPassword" function for the appAuthHeader ?
private static string CalculateHashedPassword(string text)
{
var crypt = new SHA256Managed();
string hash = String.Empty;
byte[] crypto = crypt.ComputeHash(Encoding.ASCII.GetBytes(text));
foreach (byte theByte in crypto)
{
hash += theByte.ToString("x2");
}
return hash;
}
I don't see it in your script.
Vous devez vous connecter pour laisser un commentaire.
Commentaires
14 commentaires