Ejemplo n.º 1
0
        public static async Task <string> GetJWTToken(string APISecret, JWT_Payload payload)
        {
            JwtEncoder jwt          = new JwtEncoder(new HMACSHA256Algorithm(), new JsonNetSerializer(), new JwtBase64UrlEncoder());
            string     requestToken = jwt.Encode(payload, APISecret);

            HttpWebResponse response = await SendWebRequest(HttpMethod.Post, TWPApiUtil.Auth_Service_EndPoint, requestToken, null);

            if (response.StatusCode == HttpStatusCode.Created)
            {
                JObject result = null;

                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    string responseString = await sr.ReadToEndAsync();

                    result = JObject.Parse(responseString);

                    string authToken = result["token"].ToString();

                    return(authToken);
                }
            }

            throw new InvalidOperationException($"Received an error while requesting a JWT token: {response.StatusCode} - {response.StatusDescription}");
        }
Ejemplo n.º 2
0
        public static async Task <string> getSSOLink(string APISecret, int partnerId, int siteId, string APIToken, APIProduct ssoType, string ssoUserIdenfitier)
        {
            JWT_Payload ssoPayload = new JWT_Payload(partnerId, siteId, ssoType)
            {
                User = new JWT_UserInfo(ssoUserIdenfitier)
            };

            string ssoURL = TWPApiUtil.Base_Employee_SSO_EndPoint;

            if (ssoType == APIProduct.TWP_Supervisor_SSO)
            {
                ssoURL = TWPApiUtil.Base_Supervisor_SSO_EndPoint;
                ssoPayload.User.Type = JWT_Payload.JWT_Supervisor_Type_ID;
            }

            return(ssoURL + await GetJWTToken(APISecret, ssoPayload));
        }