// GET: Sso
        public ActionResult Callback()
        {
            // Create a callback model with all the relevant information
            var callback = new SsoCallbackModel {
                SsoCode = Request.Params["code"],
                State   = Request.Params["state"] ?? "add"
            };

            var token        = Esi.Auth.GetTokenComposite(callback.SsoCode, TokenAuthenticationType.VerifyAuthCode);
            var tokenWrapper = new DbTokenWrapper(token);

            callback.TokenUuid = tokenWrapper.Uuid;
            TokenCache.Add(tokenWrapper);

            var status = callback.State;

            switch (status)
            {
            case "add":
                return(RedirectToAction("AddTokenToDb", callback));

            case "signup":
                return(RedirectToAction("SignUpStepComplete", callback));

            case "signin":
                return(RedirectToAction("SignIn", callback));

            default:
                return(RedirectToAction("AddTokenToDb", callback));
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Refreshes a token and updates it in the database.
        /// </summary>
        /// <param name="token"></param>
        public static void RefreshToken(DbTokenWrapper token)
        {
            var context = new AppDbContext();

            token.RefreshToken();
            context.Tokens.AddOrUpdate((DbTokenWrapper)token);
            context.SaveChanges();
        }
        public static IEsiTokenContainer RefreshToken(this DbTokenWrapper token)
        {
            var context = new AppDbContext();
            var result  = Esi.Auth.RefreshToken(token);

            context.Tokens.AddOrUpdate(token);
            context.SaveChanges();
            return(result);
        }
        public static string GetAccessToken(this DbTokenWrapper token)
        {
            var context = new AppDbContext();
            var result  = Esi.Auth.GetAccessToken(token);

            context.Tokens.AddOrUpdate(token);
            context.SaveChanges();
            return(result);
        }
Beispiel #5
0
        public static async Task <string> GetAccesToken(int characterId, params string[] scopes)
        {
            var            context = new AppDbContext();
            var            tokens  = context.Tokens.Where(t => t.CharacterId == characterId);
            DbTokenWrapper token   = null;

            foreach (var t in tokens)
            {
                if (Esi.Auth.CheckScope(t, scopes))
                {
                    token = t;
                }
            }

            var accesssToken = token?.GetAccessToken();
            await context.SaveChangesAsync();

            return(accesssToken);
        }