protected string GetExpireURL() { var ru = new RequestUrl($"http://{Backend.BASE_URL}/connect/authorize"); var url = ru.CreateEndSessionUrl(idTokenHint: _idToken); return(url); }
public static string EndSession() { string IdTokenHint = System.Web.HttpContext.Current.Session["IdTokenHint"].ToString(); // HttpContext.Current.GetOwinContext().Authentication.SignOut(); // HttpContext.Current.Response.Cookies.Remove() // HttpContext.Current.GetOwinContext().Response.Cookies.Delete("ASP.NET_SessionId"); // var A_t = HttpContext.Current.GetOwinContext();//.Authentication.User.Identity.AuthenticationType; var ru = new RequestUrl("https://upravbot.ru/IDS4/connect/endsession"); //////("https://upravbot.ru/IDS4/signout-callback-oidc");//("http://localhost:5002/signout-callback-oidc");// ////http://localhost:5002/connect/endsession?id_token_hint=1C56BDD4F94136364F7241401EAF65CDAAA325B776191E08121D7B2F2583EA34 //try //{ var url = ru.CreateEndSessionUrl(IdTokenHint, "http://localhost:5002/signout-callback-oidc"); var url_2 = "https://upravbot.ru/IDS4/Account/Logout?logoutId=" + IdTokenHint + ""; HttpContext.Current.Response.Redirect(url_2, false); // HttpContext.Current.Response.Redirect(url, false); HttpContext.Current.GetOwinContext().Authentication.SignOut("ApplicationCookie"); //} //catch (Exception ex) //{ // string a = ex.Message; // /* // 1. Could not load file or assembly 'System.Text.Encodings.Web, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. // 2. The type initializer for 'System.Text.Encodings.Web.DefaultUrlEncoder' threw an exception. // 3. Could not load file or assembly 'System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. // */ //} //string b = ""; //string sessionResponseAsync = null; //var ru = new RequestUrl("https://upravbot.ru/IDS4/endsession"); //Task.Run(async () => { // sessionResponseAsync = ru.CreateEndSessionUrl(accessToken, "/ClientLogin.aspx"); //}); //var client = new HttpClient(); //UserInfoResponse SessionResponse = null; //CancellationTokenSource source = new CancellationTokenSource(); //source.CancelAfter(TimeSpan.FromSeconds(1)); //Task.Run(async () => //{ // SessionResponse = await client.GetUserInfoAsync(new UserInfoRequest // { // Address = "https://upravbot.ru/IDS4/signout-callback-oidc",//"http://localhost:5002/signout-callback-oidc", // Token = accessToken // }).ConfigureAwait(false); //}).GetAwaiter().GetResult(); return("");//sessionResponseAsync;// SessionResponse;//ru; }
public async Task <string> CreateLogoutUrlAsync(HttpContext context, string idTokenHint) { await LoadEndpointsAsync(); var originalPathBase = context.Features.Get <IAuthenticationFeature>()?.OriginalPathBase ?? context.Request.PathBase; var postLogoutRedirectUri = context.Request.Scheme + "://" + context.Request.Host + originalPathBase + signedOutCallbackPath; var ru = new RequestUrl(authorizeEndpoint); var pkce = GeneratePKCEValues(); var url = ru.CreateEndSessionUrl( idTokenHint: idTokenHint, postLogoutRedirectUri: postLogoutRedirectUri); return(url); }
public async Task <IActionResult> Logout() { await HttpContext.SignOutAsync(Startup.CookieScheme); var endsessionEndpoint = $"{_generalSettings.Authority}/connect/endsession"; var requestUrl = new RequestUrl(endsessionEndpoint); var idToken = await HttpContext.GetTokenAsync(OidcConstants.ResponseTypes.IdToken); var endSessionUrl = requestUrl.CreateEndSessionUrl( idTokenHint: idToken, postLogoutRedirectUri: $"{_generalSettings.Host}{Url.Action(nameof(LoggedOut), Name)}" ); return(View(new LogoutViewModel { Url = endSessionUrl })); }
public static void EndSession() { // At this point we have already sign out by using FormsAuthentication and we also have to sign out from Identity Server. // Create the url to Identity Server's end session endpoint. var endsessionEndpoint = OAuthConfiguration.Authority.TrimEnd('/') + "/connect/endsession"; var requestUrl = new RequestUrl(endsessionEndpoint); var endSessionUrl = requestUrl.CreateEndSessionUrl( idTokenHint: HttpContext.Current.GetToken(OidcConstants.ResponseTypes.IdToken), postLogoutRedirectUri: OAuthConfiguration.Host ); if (!HttpContext.Current.Response.IsRequestBeingRedirected) { HttpContext.Current.Response.Redirect(endSessionUrl); } HttpContext.Current.ApplicationInstance.CompleteRequest(); }
public async Task <string> EndSessionUrl([FromBody] IdentityData data) { using (HttpClient client = httpClientFactory.CreateClient()) { DiscoveryResponse disco = await client.GetDiscoveryDocumentAsync(Utils.Linked.Identity); if (disco.IsError) { return(null); } var ru = new RequestUrl(disco.EndSessionEndpoint); string url = ru.CreateEndSessionUrl( idTokenHint: data.IdentityToken, state: data.State, postLogoutRedirectUri: Utils.ClientIdentityEndSessionRedirectUri ); return(url); } }