Example #1
0
        public async Task <(IOauthToken token, string owner)> RefreshToken(string refreshToken, IScope scope)
        {
            IOauthToken token = (IOauthToken) await GetToken(refreshToken, scope);

            IJwtToken jwtToken = await validationManager.ValidateTokenAsync(token);

            return(token, jwtToken.Name);
        }
Example #2
0
        void AddToken(string owner, IOauthToken token)
        {
            if (!userTokens.TryGetValue(owner, out List <IOauthToken> tokens))
            {
                tokens            = new List <IOauthToken>();
                userTokens[owner] = tokens;
            }

            tokens.Add(token);
        }
Example #3
0
        public async Task <IToken> GetToken(string user, IScope scope)
        {
            IOauthToken token = userTokens[user].Find(a => a.Scope.IsSubset(scope));

            if (token?.Expires > DateTime.UtcNow)
            {
                token = await RefreshToken(token);
            }

            return(token);
        }
Example #4
0
        public async Task <(IOauthToken token, string owner)> ListenForResponse(IScope scope, AuthUrl authUrl)
        {
            IAuthResponse response = await responseManager.AwaitResponse(20000);

            if (authUrl.State != response.State)
            {
                throw new Exception("Invalid auth response state.");
            }

            IOauthToken token = await GetToken(response, authUrl, scope);

            IJwtToken jwtToken = await validationManager.ValidateTokenAsync(token);

            return(token, jwtToken.Name);
        }
Example #5
0
        public async Task <(IOauthToken token, string owner)> GetToken(IScope scope)
        {
            AuthUrl       authUrl  = GenerateAuthUrl(scope.ScopeString);
            IAuthResponse response = await responseManager.GetResponse(authUrl.Url, 10000);

            if (authUrl.State != response.State)
            {
                throw new Exception("Invalid auth response state.");
            }

            IOauthToken token = await GetToken(response, authUrl, scope);

            IJwtToken jwtToken = await validationManager.ValidateTokenAsync(token);

            return(token, jwtToken.Name);
        }
Example #6
0
        public Task EsiGetTokenInfo(int user, int token)
        {
            IList <string> users = EsiLogin.GetUsers();

            if (user < 0 || user >= users.Count)
            {
                return(RespondAsync("User index out of bounds.", false, false));
            }

            IList <IToken> tokens = EsiLogin.GetTokens(users[user]);

            if (token < 0 || token >= users.Count)
            {
                return(RespondAsync("Token index out of bounds.", false, false));
            }

            IOauthToken oauthToken = tokens[token] as IOauthToken;

            return(RespondAsync($"```" +
                                $"{DateTime.UtcNow}\n" +
                                $"{users[user]}:\n" +
                                $"	AccessToken: {oauthToken.AccessToken[^10..^0]}\n"+
Example #7
0
        public async Task <IJwtToken> ValidateTokenAsync(IOauthToken token)
        {
            IJwtToken jwtToken;

            using (HttpResponseMessage response = await client.GetAsync(config.JwtKeySetEndpoint))
            {
                Stream stream = await response.Content.ReadAsStreamAsync();

                JwtKeySet keySet = await JsonSerializer.DeserializeAsync <JwtKeySet>(stream);

                var headers = JWT.Headers(token.AccessToken);
                var jwk     = keySet.Keys[1];

                RSACryptoServiceProvider key = new RSACryptoServiceProvider();
                key.ImportParameters(new RSAParameters
                {
                    Modulus  = Base64Url.Decode(jwk.n),
                    Exponent = Base64Url.Decode(jwk.e)
                });

                jwtToken = JWT.Decode <JwtToken>(token.AccessToken, key);

                if (jwtToken.Issuer != "login.eveonline.com")
                {
                    throw new Exception("Invalid JWT Token!");
                }

                uint unixTimestamp = (uint)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                if (jwtToken.Expiery < unixTimestamp)
                {
                    throw new Exception("Invalid JWT Token");
                }
            }

            return(jwtToken);
        }
Example #8
0
 public Task <IOauthToken> RefreshToken(IOauthToken token)
 {
     return(AddToken(token.RefreshToken, token.Scope));
 }