コード例 #1
0
ファイル: GetThreats.cs プロジェクト: sketabchi-mobiz/Cylance
        private static string GenerateAuthorizationToken(JwtClaims jwtClaims, string appSecret)
        {
            if (jwtClaims == null)
            {
                throw new ArgumentNullException(nameof(jwtClaims));
            }

            if (string.IsNullOrWhiteSpace(appSecret))
            {
                throw new ArgumentException(nameof(appSecret));
            }

            var algorithm  = new HMACSHA256Algorithm();
            var serializer = new JsonNetSerializer();
            var encoder    = new JwtBase64UrlEncoder();
            var jwt        = new JwtEncoder(algorithm, serializer, encoder);

            return(jwt.Encode(jwtClaims, appSecret));
        }
コード例 #2
0
ファイル: GetThreats.cs プロジェクト: sketabchi-mobiz/Cylance
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            const string tenantId  = "ba50714d-f006-47db-9420-fcc0b00666e3";
            const string appId     = "d4146a43-6826-40f3-b136-67de6f996c71";
            const string appSecret = "c8710d12-083c-4c4a-98ff-0b3e5be18247";

            var utcNow    = DateTimeOffset.UtcNow;
            var jwtClaims = new JwtClaims
            {
                iss = "http://cylance.com",
                jti = Guid.NewGuid().ToString(),
                iat = utcNow.ToUnixTimeSeconds(),
                exp = (utcNow).AddSeconds(1800).ToUnixTimeSeconds(),
                tid = tenantId,
                sub = appId
            };

            try
            {
                var authToken = GenerateAuthorizationToken(jwtClaims, appSecret);
                Console.WriteLine($"\n[Authorization Token]\n{authToken}\n");

                var accessToken = GenerateAccessToken(authToken);
                Console.WriteLine($"\n[Access Token]\n{accessToken}\n");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(jsonResponse, Encoding.UTF8, "application/json")
            });
        }