private string BuildEasyLogoutUrl(LogoutParams option = null)
 {
     // TODO: 所有的 url 都使用 Flurl 完成拼接,可读性更强
     if (option?.RedirectUri != null)
     {
         return($"{Host}/login/profile/logout?redirect_uri={option.RedirectUri}");
     }
     return($"{Host}/login/profile/logout");
 }
 private string BuildCasLogoutUrl(LogoutParams option = null)
 {
     // TODO: 所有的 url 都使用 Flurl 完成拼接,可读性更强
     if (option?.RedirectUri != null)
     {
         return($"{Host}/cas-idp/logout?url={option.RedirectUri}");
     }
     return($"{Host}/cas-idp/logout");
 }
 private string BuildOidcLogoutUrl(LogoutParams option = null)
 {
     if ((option?.RedirectUri == null && option?.IdToken != null) || (option?.RedirectUri != null && option?.IdToken == null))
     {
         throw new Exception("必须同时传入 idToken 和 redirectUri 参数,或者同时都不传入");
     }
     // TODO: 所有的 url 都使用 Flurl 完成拼接,可读性更强
     if (option?.RedirectUri != null)
     {
         return($"{Host}/oidc/session/end?url=id_token_hint={option.IdToken}&post_logout_redirect_uri={option.RedirectUri}");
     }
     return($"{Host}/oidc/session/end");
 }
        public string BuildLogoutUrl(LogoutParams option = null)
        {
            if (Options?.Protocol == Protocol.CAS)
            {
                return(BuildCasLogoutUrl(option));
            }

            if ((Options?.Protocol == Protocol.OIDC) && (bool)option?.Expert)
            {
                return(BuildOidcLogoutUrl(option));
            }

            return(BuildEasyLogoutUrl(option));
        }
Beispiel #5
0
        /// <summary>
        /// Performs logout from backend.
        /// </summary>
        public static async Task Logout()
        {
            try
            {
                // Resolve backend service
                var partnerBackendService = new BackendService(new Uri(BackendUrl));
                var logoutParams          = new LogoutParams(AccessToken);

                // Logout from backend
                await partnerBackendService.LogoutAsync(logoutParams).ConfigureAwait(false);
            }
            catch
            {
                // Ignored
            }
        }
        public async Task <IActionResult> Logout([FromBody] LogoutParams logout)
        {
            if ((RoleType)int.Parse(User.FindFirst(x => x.Type == ClaimsIdentity.DefaultRoleClaimType).Value) ==
                RoleType.Guest)
            {
                return(new BadResponseResult($"You are a guest."));
            }

            if (!int.TryParse(User.FindFirst(x => x.Type == ClaimsIdentity.DefaultNameClaimType)?.Value ?? "-1",
                              out var userId) || userId == -1)
            {
                return(new ResponseResult((int)HttpStatusCode.NotFound, "We can not find your id."));
            }

            if (await _authService.LogOutAsync(userId, logout.RefreshToken))
            {
                return(new OkResponseResult("Account is logged out of the system"));
            }
            return(new ResponseResult((int)HttpStatusCode.InternalServerError, "Account is NOT logged out of the system"));
        }
 public void Logout(LogoutParams logoutParams)
 {
     var response = factory
                    .GetRequest(logoutParams)
                    .Send <LogoutParams>(serviceUrl);
 }