Base solution for your next web application

Activities of "maliming"

hi


public async Task<ActionResult> Logout(string returnUrl = "")
{
    var scheme = "";
    var external = await HttpContext.AuthenticateAsync(IdentityConstants.ExternalScheme);
    if (!external.Succeeded)
    {
        return await AfterLogout();
    }

    scheme = external.Properties.Items["zero_scheme"];
    var openIdConnectOptions = HttpContext.RequestServices.GetRequiredService<IOptionsMonitor<OpenIdConnectOptions>>();
    var options = openIdConnectOptions.Get("OpenIdConnect");

    if (scheme == "auth0")
    {
        options.ClientId = "ZTl49s6ZXt535L5SqbfoOk0gYpu8njAQ";
        options.ClientSecret = "vnnDHxuMwSKF7hkrzYrJigfDGIL7XuAw3dSmSdZRCJ7zAO7ObIVR8j9hYGrsau1E";
        options.Authority = "https://abpframework.us.auth0.com";
        options.MetadataAddress = "https://abpframework.us.auth0.com/.well-known/openid-configuration";
        options.ResponseType = "code";
        options.Scope.Clear();
        options.Scope.Add("openid");
        options.Scope.Add("profile");
        options.Scope.Add("email");

        options.ConfigurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(options.MetadataAddress, new OpenIdConnectConfigurationRetriever(),
            new HttpDocumentRetriever(options.Backchannel)
            {
                RequireHttps = options.RequireHttpsMetadata
            })
        {
            RefreshInterval = options.RefreshInterval,
            AutomaticRefreshInterval = options.AutomaticRefreshInterval,
        };

        using (openIdConnectOptions.As<TenantBasedOpenIdConnectOptions>().Change(options))
        {
            var authenticationHandlerProvider = HttpContext.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>().As<MyOpenIdAuthenticationHandlerProvider>();
            authenticationHandlerProvider.HandlerMap.Remove("OpenIdConnect");

            var authProperties = new AuthenticationProperties
            {
                RedirectUri = "/Account/AfterLogout?returnUrl=" + Uri.EscapeDataString(returnUrl)
            };

            return new SignOutResult(OpenIdConnectDefaults.AuthenticationScheme, authProperties);
        }
    }
    else
    {
        var authProperties = new AuthenticationProperties
        {
            RedirectUri = "/Account/AfterLogout?returnUrl=" + Uri.EscapeDataString(returnUrl)
        };

        return new SignOutResult(OpenIdConnectDefaults.AuthenticationScheme, authProperties);
    }
}

public async Task<ActionResult> AfterLogout(string returnUrl = "")
{
    await _signInManager.SignOutAsync();
    var userIdentifier = AbpSession.ToUserIdentifier();

    if (userIdentifier != null &&
        _settingManager.GetSettingValue<bool>(AppSettings.UserManagement.AllowOneConcurrentLoginPerUser))
    {
        var user = await _userManager.GetUserAsync(userIdentifier);
        await _userManager.UpdateSecurityStampAsync(user);
    }

    if (!string.IsNullOrEmpty(returnUrl))
    {
        returnUrl = NormalizeReturnUrl(returnUrl);
        return Redirect(returnUrl);
    }

    return RedirectToAction("Login");
}

hi

@maliming Is there any update on this? Can you provide me some more detail for this

https://github.com/maliming/CDP-Base-Zero-13.0.0/commit/0a670f26fb9d6ebb506899230cb0cf60b06efd8b

hi

I am facing below ss when I login through auth0.

Please add a new action in AccountController

public async Task Logout(string returnUrl = "")
{
    var scheme = "";
    var external = await HttpContext.AuthenticateAsync(IdentityConstants.ExternalScheme);
    if (external.Succeeded)
    {
        scheme = external.Properties.Items["zero_scheme"];
    }

    var openIdConnectOptions = HttpContext.RequestServices.GetRequiredService<IOptionsMonitor<OpenIdConnectOptions>>();
    var options = openIdConnectOptions.Get("OpenIdConnect");

    if (scheme == "auth0")
    {
        options.ClientId = "ZTl49s6ZXt535L5SqbfoOk0gYpu8njAQ";
        options.ClientSecret = "vnnDHxuMwSKF7hkrzYrJigfDGIL7XuAw3dSmSdZRCJ7zAO7ObIVR8j9hYGrsau1E";
        options.Authority = "https://abpframework.us.auth0.com";
        options.MetadataAddress = "https://abpframework.us.auth0.com/.well-known/openid-configuration";
        options.ResponseType = "code";
        options.Scope.Clear();
        options.Scope.Add("openid");
        options.Scope.Add("profile");
        options.Scope.Add("email");

        options.ConfigurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(options.MetadataAddress, new OpenIdConnectConfigurationRetriever(),
            new HttpDocumentRetriever(options.Backchannel)
            {
                RequireHttps = options.RequireHttpsMetadata
            })
        {
            RefreshInterval = options.RefreshInterval,
            AutomaticRefreshInterval = options.AutomaticRefreshInterval,
        };

        using (openIdConnectOptions.As<TenantBasedOpenIdConnectOptions>().Change(options))
        {
            var authenticationHandlerProvider = HttpContext.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>().As<MyOpenIdAuthenticationHandlerProvider>();
            authenticationHandlerProvider.HandlerMap.Remove("OpenIdConnect");

            var authProperties = new AuthenticationProperties
            {
                RedirectUri = "/Account/AfterLogout?returnUrl=" + Uri.EscapeDataString(returnUrl)
            };

            await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, authProperties);
        }
    }
    else
    {
        var authProperties = new AuthenticationProperties
        {
            RedirectUri = "/Account/AfterLogout?returnUrl=" + Uri.EscapeDataString(returnUrl)
        };

        await HttpContext.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme, authProperties);
    }
}

public async Task<ActionResult> AfterLogout(string returnUrl = "")
{
    await _signInManager.SignOutAsync();
    var userIdentifier = AbpSession.ToUserIdentifier();

    if (userIdentifier != null &&
        _settingManager.GetSettingValue<bool>(AppSettings.UserManagement.AllowOneConcurrentLoginPerUser))
    {
        var user = await _userManager.GetUserAsync(userIdentifier);
        await _userManager.UpdateSecurityStampAsync(user);
    }

    if (!string.IsNullOrEmpty(returnUrl))
    {
        returnUrl = NormalizeReturnUrl(returnUrl);
        return Redirect(returnUrl);
    }

    return RedirectToAction("Login");
}

hi

Can you share a test "providerKey": "auth0|USER_ID","providerAccessCode": "Auth0_ID_Token",?

I will test this api.

hi

This commit will fix your logout problem. It will log out auth0 at the same time.

https://github.com/maliming/CDP-Base-Zero-13.0.0/commit/aa489062c43ace937d2e602e5c29fa6ec4f49039

Yes,

same error

Client id : jhIfmTUP3vddUEglxXYF16LaDJ2nFpxy Authority: https://fynauth0.uk.auth0.com

You can copy the code from API website to MVC

hi

when I logout from the application, then it redirects me back to the login screen but in actual it doesn't logout me from the auth0

I will share code to fix this.

but can you add https://localhost:44302/signout-callback-oidc as post_logout_redirect_uri in your auth0 website?

invalid_request: The "post_logout_redirect_uri" querystring parameter "https://localhost:44302/signout-callback-oidc" is not defined as a valid URL in "Allowed Logout URLs". To add a new URL, please do it here: https://manage.auth0.com/#/account/advanced

hi

Unknown external auth provider: OpenIdConnect"

This is because we only add OpenIdConnectExternalLoginInfoProvider in web.host project in instead of web.mvc

Maybe you shouldn't use /api/TokenAuth/ExternalAuthenticate in web.mvc project

hi

Add a new hidden input in your ExternalLogin form. you can change it by js code.

Then you can get this value in OnRedirectToIdentityProvider method.

Showing 21 to 30 of 3041 entries