/// <summary> /// Updates the access token, or sets an error flag if the token could no longer be /// obtained. /// </summary> private void OnAccessToken(JsonResult <AccessResponse> result) { AccessResponse response = result.Result; m_queried = true; if (result.HasError) { // If it errors out, avoid checking again for another 5 minutes m_keyExpires = DateTime.UtcNow.AddMinutes(5.0); EveMonClient.Notifications.NotifySSOError(result); HasError = true; m_queryPending = false; EveMonClient.OnESIKeyInfoUpdated(this); } else { AccessToken = response.AccessToken; // PKCE routinely updates refresh tokens RefreshToken = response.RefreshToken; m_keyExpires = response.ExpiryUTC; // Have to make a second request for the character information! SSOAuthenticationService.GetTokenInfo(AccessToken, OnTokenInfo); } }
/// <summary> /// Constructor for new ESI credential. /// </summary> public EsiKeyUpdateOrAdditionWindow() { InitializeComponent(); m_server = new SSOWebServer(); m_state = DateTime.UtcNow.ToFileTime().ToString(); m_authService = SSOAuthenticationService.GetInstance(); }
/// <summary> /// Tries to add or update the ESI key. /// </summary> /// <param name="id">The id.</param> /// <param name="accessResponse">The access and refresh token.</param> /// <param name="callback">The callback.</param> public static void TryAddOrUpdateAsync(long id, AccessResponse accessResponse, EventHandler <ESIKeyCreationEventArgs> callback) { accessResponse.ThrowIfNull(nameof(accessResponse)); SSOAuthenticationService.GetTokenInfo(accessResponse.AccessToken, (result) => callback(null, new ESIKeyCreationEventArgs(id, accessResponse. RefreshToken, result))); }
private void SignInUser(bool createPersistentCookie, string user) { if (WebSecurity.UserExists(user)) { int timeout = createPersistentCookie ? 43200 : 30; var cookie = SSOAuthenticationService.CreateFormsAuthenticationCookie(user, timeout, createPersistentCookie); HttpContext.Response.Cookies.Add(cookie); } }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) //simple login { var username = SSOAuthenticationService.EncryptToken(model.UserName); return Redirect(model.ReturnUrl + "?token=" + username + "&createPersistentCookie=" + (model.RememberMe ? "true" : "false")); } return View(model); }
public void Logoff(string token) { if (!string.IsNullOrEmpty(token)) { var user = SSOAuthenticationService.DecryptToken(token); if (WebSecurity.UserExists(user)) { WebSecurity.Logout(); } } }
public void Login(string token) { const bool createPersistentCookie = false; if (!string.IsNullOrEmpty(token)) { var user = SSOAuthenticationService.DecryptToken(token); if (WebSecurity.UserExists(user)) { SignInUser(createPersistentCookie, user); } } }
public ActionResult LoginWithToken(string token, bool createPersistentCookie) { var user = SSOAuthenticationService.DecryptToken(token); if (WebSecurity.UserExists(user)) { int timeout = createPersistentCookie ? 43200 : 30; var cookie = SSOAuthenticationService.CreateFormsAuthenticationCookie(user, timeout, createPersistentCookie); HttpContext.Response.SetCookie(cookie); } return(RedirectToAction("Index", "Home")); }
/// <summary> /// Starts obtaining an access token from the refresh token, because either the access /// token expired or was never obtained. /// </summary> internal void CheckAccessToken() { var rt = RefreshToken; if (m_keyExpires < DateTime.UtcNow && !string.IsNullOrEmpty(rt)) { var auth = SSOAuthenticationService.GetInstance(); if (auth == null) { // User removed the client ID / secret HasError = true; } else { auth.GetNewToken(rt, OnAccessToken); } } }
public ActionResult Login(string returnUrl) { //check if we are already logged in and if not then login var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie == null) { var model = new LoginModel() { ReturnUrl = returnUrl }; return View(model); } else { var ticket = FormsAuthentication.Decrypt(authCookie.Value); var user = SSOAuthenticationService.EncryptToken(ticket.Name); return Redirect(returnUrl + "?token=" + user + "&createPersistentCookie=true"); } }
public SingleSignOnController() { this.ssoAuthenticationService = new SSOAuthenticationService(); }