Ejemplo n.º 1
0
        public ActionResult <string> Get(string code)
        {
            try
            {
                _ = code ?? throw new ArgumentNullException(nameof(code));

                string   codeString = HttpUtility.UrlDecode(code);
                string[] codes      = config.GetSecurityCodes();

                if (codes.Contains(codeString))
                {
                    List <Claim> claims = new List <Claim> {
                        new Claim($"{config.ManagementApiIssuer}/name", Guid.NewGuid().ToString()),
                        new Claim($"{config.ManagementApiIssuer}/role", "manage")
                    };
                    JsonWebToken jwt = new JsonWebToken(config.ManagmentApiSymmetricKey, claims, 120.0,
                                                        config.ManagementApiIssuer, config.ManagementApiAudience);
                    logger?.LogInformation("Returning security token.");

                    return(StatusCode(200, jwt.ToString()));
                }

                logger?.LogWarning("Security code mismatch attempting to acquire security token.");
                throw new IndexOutOfRangeException("Invalid code");
            }
            catch (Exception ex)
            {
                logger?.LogError(ex, "Error obtaining security token.");
                return(StatusCode(500, ex.Message));
            }
        }
Ejemplo n.º 2
0
        public ActionResult <string> Get(string code)
        {
            string codeString = HttpUtility.UrlDecode(code);

            string[] codes = config.GetSecurityCodes();

            if (codes.Contains(codeString))
            {
                List <Claim> claims = new List <Claim>();
                claims.Add(new Claim("http://www.skunklab.io/name", Guid.NewGuid().ToString()));
                claims.Add(new Claim("http://www.skunklab.io/role", "manage"));
                //build the JWT token
                //JsonWebToken jwt = new JsonWebToken(new Uri(), config.Security.WebApi.SymmetricKey, config.Security.WebApi.Issuer, claims, 120.0);
                JsonWebToken jwt = new JsonWebToken(config.ManagmentApiSymmetricKey, claims, 120.0, config.ManagementApiIssuer, config.ManagementApiAudience);
                return(jwt.ToString());
            }
            else
            {
                throw new IndexOutOfRangeException("Invalid code");
            }
        }