Esempio n. 1
0
        private static void CreateMostBasicTokenSnippet()
        {
            // using GuylianGilsing.JWT.Tokens;
            // using GuylianGilsing.JWT.Hashing;
            // using GuylianGilsing.JWT.Hashing.Algorithms;

            // Create a new token
            Token token = new Token();

            // Register payload claims
            token.payload.RegisterClaim("iss", "https://example.com");
            token.payload.RegisterClaim("sub", "code_snippet");
            token.payload.RegisterClaim("aud", "github");

            // Set the hashing algorithm
            token.hashAlgo = new Sha256Algo();

            // Set the secret key
            token.secretKey = new Key("MySuperSecretKey");

            // Sign the token
            TokenSigner signer      = new TokenSigner();
            string      signedToken = signer.Sign(token);

            // Sign the token with a seperate key
            string otherSignedToken = signer.Sign(token, new Key("OtherKey"));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            // Create a new token
            Token token = new Token();

            // Register payload claims
            token.payload.RegisterClaim("iss", "https://example.com");

            // Set the hashing algorithm
            token.hashAlgo = new Sha256Algo();

            // Set the secret key
            token.secretKey = new Key("MyKey");

            // Sign the token
            TokenSigner signer      = new TokenSigner();
            string      signedToken = signer.Sign(token);

            Console.WriteLine(signedToken);

            Console.ReadLine();
        }