Top

Connecting rest api to C#

Answered

Comments

14 comments

  • Official comment
    Vincent BAILLEAU

    Hi Mahajir,

    In order to user an application id in production platform, you have to deploy it before.

    Regards

    Vincent

    Comment actions Permalink
  • Vincent BAILLEAU

    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

    0
    Comment actions Permalink
  • Mahajir Taqarrub

    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

    0
    Comment actions Permalink
  • Mahajir Taqarrub

    I've deployed it. I tried using JavaScript and it worked.

    0
    Comment actions Permalink
  • Vincent BAILLEAU

    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")
            }
        }
    }

    0
    Comment actions Permalink
  • Mahajir Taqarrub

    I think I use the right sha256 algorithm. because when I compare it on the web, the result is the same.

    about your script, I can't use io.swager.api and io.swager.model and also AuthenticationApi and GetBasicLoginSuccess.

    0
    Comment actions Permalink
  • Pascal BORSCHNECK

    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

    0
    Comment actions Permalink
  • Mahajir Taqarrub

    I think the appID that I use is already deployed and should be used for production right?

    and I think the problem is in the script but I don't know how to solve it. because when I use javascript, it works.

    btw thanks for your response.

    0
    Comment actions Permalink
  • Pascal BORSCHNECK

    Hi,

    You said

    the problem is in the script

    Which script ?  Your

    ?
    Did you change there the, I suppose, constant URL_LOGIN from sandbox to prod ?

     

    And what is at line 116 (cf your logs)

    0
    Comment actions Permalink
  • Pascal BORSCHNECK

    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 ?

    0
    Comment actions Permalink
  • Mahajir Taqarrub

    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.

     

    0
    Comment actions Permalink
  • Pascal BORSCHNECK

    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.

    0
    Comment actions Permalink
  • Mahajir Taqarrub

    this is my sha256 function

    0
    Comment actions Permalink
  • Pascal BORSCHNECK

    ...

    Strange.  As it worked here for Vincent with swagger, could you please use it instead of unity3d?

    Or ask help to unity3d ?

    0
    Comment actions Permalink

Please sign in to leave a comment.

Still can't find what you need?

  • Contact Us

    Do you have any question about Rainbow? Leave us a message to get more information.

    Contact
  • Ask the Community

    Do you need help? Ask your questions to the Community and get answers from other Rainbow users.

    Post message