Unable to get access token and refresh token from Android Poynt SDK?

I am not able to get exact access token and refresh token from SDK.
As per poynt concept the access token will expire for every 24 hrs. So we can get new access token using refresh token.
If I use IPoyntTokenService generated access token not able to get Catalogs using API call and showing refresh token as invalid to get new tokens.
If I use AccountManager not able to get refresh token getting access token only.

FYI: IPoyntTokenService ,AccountManager generated access tokens are different lengths.

My concept is I want to store Access toke and Refresh token in our DB and using refresh token I want to get new tokens using API calls for every 24 hours without depending on SDK.

FYI: We are using HTTP web request for API calls because we don’t have code to implement in .NET
Can you please help me to solve this issue.

Hi Prasad,

You shouldn’t try to get the access token from the terminal. Instead create a self-signed JWT and get an access token as described in https://poynt.github.io/developer/cloud/integrating-with-poynt-cloud-apis.html

Hi Dennis,

For generating self-signed JWT we are using Chilkat RS256 algorithm code in .NET. Using this Chilkat we are facing 2 issues

  1. Need to purchase or 30 days trail version.

  2. Using trail version we got access token and refresh token but refresh token is invalid when I try to get new tokens and the length is greater.
    Can you please help me to get valid tokens in any other ways…
    Here is the sample code for generating JWT
    ///////
    Chilkat.Global glob = new Chilkat.Global();
    bool success1 = glob.UnlockBundle(“Anything for 30-day trial”);
    if ( success1 != true )
    {
    Console.WriteLine(glob.LastErrorText);
    return;
    }

     //  The LastErrorText can be examined in the success case to see if it was unlocked in
     //  trial more, or with a purchased unl
     Chilkat.PrivateKey privKey = new Chilkat.PrivateKey();
     //  Load an RSA private key from a PEM file.
     bool success = privKey.LoadEncryptedPemFile("publicprivatekey.pem", "passwd");
     if ( success != true )
     {
         Console.WriteLine(privKey.LastErrorText);
         return;
     }
     Chilkat.Jwt jwt = new Chilkat.Jwt();
    
     //  Build the JOSE header
     Chilkat.JsonObject jose = new Chilkat.JsonObject();
     //  Use RS256.  Pass the string "RS384" or "RS512" to use RSA with SHA-384 or SHA-512.
     success = jose.AppendString("alg", "RS256");
     success = jose.AppendString("typ", "JWT");
     //  Now build the JWT claims (also known as the payload)
     Chilkat.JsonObject claims = new Chilkat.JsonObject();
     success = claims.AppendString("iss", "APPId");
     success = claims.AppendString("sub", "APPId");
     success = claims.AppendString("aud", "https://services.poynt.net");
     success = claims.AppendString("jti", ( System.Guid.NewGuid() ).ToString());
    
     //  Set the timestamp of when the JWT was created to now.
     int curDateTime = jwt.GenNumericDate(0);
     success = claims.AddIntAt(-1, "iat", curDateTime);
    
     //  Set the "not process before" timestamp to now.
     // success = claims.AddIntAt(-1,"nbf",curDateTime);
    
     //  Set the timestamp defining an expiration time (end time) for the token
     //  to be now + 1 hour (3600 seconds)
     success = claims.AddIntAt(-1, "exp", curDateTime + 3);
    
     //  Produce the smallest possible JWT:
     jwt.AutoCompact = true;
    
     //  Create the JWT token.  This is where the RSA signature is created.
     string JWTtoken = jwt.CreateJwtPk(jose.Emit(), claims.Emit(), privKey);
      Console.WriteLine(JWTtoken);
    
     try
      {
         ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
         string BaseUrl = "https://services.poynt.net/token";
         string AccessToken = string.Empty;
         string MerchantId = string.Empty;
         string DeviceId = "APPId";
         string Path = System.Web.HttpContext.Current.Request.Url.ToString();
         HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create(BaseUrl);
         request.Method = "POST";
         request.ContentType = "application/x-www-form-urlencoded";
         request.Headers.Add("Authorization", "Bearer " + JWTtoken);
         string url="https://test.com/";
         string PostData = "grantType=authorization_code&redirect_uri="+url+"&client_id="+DeviceId+"&code="+Request.QueryString["Code"].ToString();
         byte[] buf = Encoding.UTF8.GetBytes(PostData);
         request.GetRequestStream().Write(buf, 0, buf.Length);
         var response = ( HttpWebResponse ) request.GetResponse();
         var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
         Poyntaccess Poyntaccess = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Poyntaccess>(responseString);
     
     }
     catch ( WebException ex )
     {
         if ( ex.Response != null )
         {
             using ( HttpWebResponse error_response = ( HttpWebResponse ) ex.Response )
             {
                 using ( StreamReader reader = new StreamReader(error_response.GetResponseStream()) )
                 {
                     string err = reader.ReadToEnd();
                 }
             }
         }
     }

Hi Prasad,

Sorry but unfortunately I am not a .net expert. Hopefully one of the other developers using this will respond.