Exemple #1
0
        public static string CreateToken(JudgePayload payload)
        {
            var key    = Encoding.UTF8.GetBytes("roo-web-service-secure-Hrjkld-423y7842.f");
            var header = new JWTHeader {
                Algorithm = "RS256"
            };

            var headerBytes  = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(header));
            var payloadBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload));

            var encodedHeader  = Base64UrlEncode(headerBytes);
            var encodedPayload = Base64UrlEncode(payloadBytes);

            var stringsToSign = encodedHeader + '.' + encodedPayload;
            var bytesToSign   = Encoding.UTF8.GetBytes(stringsToSign);

            var signatureBytes = new HMACSHA256(key).ComputeHash(bytesToSign);
            var signature      = Base64UrlEncode(signatureBytes);

            return(stringsToSign + '.' + signature);
        }
        public static JudgePayload Create(RROJudge judge, int tour, string service)
        {
            var payload = new JudgePayload
            {
                JudgeId  = judge.JudgeId,
                Status   = judge.Status,
                OpenTime = DateTime.Now,
                Tour     = tour,
                Service  = service
            };

            if (service != "androidApp")
            {
                payload.Expires = payload.OpenTime + TimeSpan.FromMinutes(40);
            }
            else
            {
                payload.Expires = DateTime.MaxValue;
            }
            return(payload);
        }