Base solution for your next web application

Activities of "maliming"

hi

The issue I am facing is I am getting external.Succeeded value as false.

Can you share your project code?

Or upload it to GitHub, then invite me to check?

https://github.com/maliming

hi

There is no bearer token in the request header.

hi

https://github.com/maliming/CDP-Base-Zero-13.0.0/blob/master/src/CDP.Web.Core/Controllers/TokenAuthController.cs#L660-L700

hi

Please share a new providerAccessCode i will test again.

The code I share is all snippets. Please re-review the code in your real project, optimize and prevent any duplication and other issues.

Thanks

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

Showing 11 to 20 of 3036 entries