Base solution for your next web application

Activities of "kansoftware"

Hi, Below is an example of the code used to open a partial view. I want to ensure versioning is applied to the ActionItem/CreateAssignedActionItem.js file.

var _createOrEditModal = new app.ModalManager({ viewUrl: abp.appPath + 'App/ActionItem/CreateAssignedActionItem', scriptUrl: abp.appPath + 'view-resources/Areas/App/Views/ActionItem/CreateAssignedActionItem.js', modalClass: 'CreateAssignedActionItem' });

$('#Create').click(function () { _createOrEditModal.open(); });

How can I include versioning in the scriptUrl for the JavaScript file to ensure that the latest version is always fetched when the partial view is loaded?

You can copy the code from API website to MVC

You mean I should copy the below section from CDPWebHostModule class to CDPWebMvcModule class

private void ConfigureExternalAuthProviders() { var externalAuthConfiguration = IocManager.Resolve<ExternalAuthConfiguration>();

if (bool.Parse(_appConfiguration["Authentication:OpenId:IsEnabled"])) 
{ 
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"])) 
    { 
        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            IocManager.Resolve&lt;TenantBasedOpenIdConnectExternalLoginInfoProvider&gt;()); 
    } 
    else 
    { 
        var jsonClaimMappings = new List&lt;JsonClaimMap&gt;(); 
        _appConfiguration.GetSection("Authentication:OpenId:ClaimsMapping").Bind(jsonClaimMappings); 

        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            new OpenIdConnectExternalLoginInfoProvider( 
                _appConfiguration["Authentication:OpenId:ClientId"], 
                _appConfiguration["Authentication:OpenId:ClientSecret"], 
                _appConfiguration["Authentication:OpenId:Authority"], 
                _appConfiguration["Authentication:OpenId:LoginUrl"], 
                bool.Parse(_appConfiguration["Authentication:OpenId:ValidateIssuer"]), 
                _appConfiguration["Authentication:OpenId:ResponseType"], 
                jsonClaimMappings 
            ) 
        ); 
    } 
} 

if (bool.Parse(_appConfiguration["Authentication:WsFederation:IsEnabled"])) 
{ 
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"])) 
    { 
        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            IocManager.Resolve&lt;TenantBasedWsFederationExternalLoginInfoProvider&gt;()); 
    } 
    else 
    { 
        var jsonClaimMappings = new List&lt;JsonClaimMap&gt;(); 
        _appConfiguration.GetSection("Authentication:WsFederation:ClaimsMapping").Bind(jsonClaimMappings); 

        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            new WsFederationExternalLoginInfoProvider( 
                _appConfiguration["Authentication:WsFederation:ClientId"], 
                _appConfiguration["Authentication:WsFederation:Tenant"], 
                _appConfiguration["Authentication:WsFederation:MetaDataAddress"], 
                _appConfiguration["Authentication:WsFederation:Authority"], 
                jsonClaimMappings 
            ) 
        ); 
    } 
} 

if (bool.Parse(_appConfiguration["Authentication:Facebook:IsEnabled"])) 
{ 
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"])) 
    { 
        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            IocManager.Resolve&lt;TenantBasedFacebookExternalLoginInfoProvider&gt;()); 
    } 
    else 
    { 
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(new FacebookExternalLoginInfoProvider( 
            _appConfiguration["Authentication:Facebook:AppId"], 
            _appConfiguration["Authentication:Facebook:AppSecret"] 
        )); 
    } 
} 

if (bool.Parse(_appConfiguration["Authentication:Twitter:IsEnabled"])) 
{ 
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"])) 
    { 
        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            IocManager.Resolve&lt;TenantBasedTwitterExternalLoginInfoProvider&gt;()); 
    } 
    else 
    { 
        var twitterExternalLoginInfoProvider = new TwitterExternalLoginInfoProvider( 
            _appConfiguration["Authentication:Twitter:ConsumerKey"], 
            _appConfiguration["Authentication:Twitter:ConsumerSecret"], 
            _appConfiguration["App:ClientRootAddress"].EnsureEndsWith('/') + "account/login" 
        ); 

        externalAuthConfiguration.ExternalLoginInfoProviders.Add(twitterExternalLoginInfoProvider); 
    } 
} 

if (bool.Parse(_appConfiguration["Authentication:Google:IsEnabled"])) 
{ 
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"])) 
    { 
        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            IocManager.Resolve&lt;TenantBasedGoogleExternalLoginInfoProvider&gt;()); 
    } 
    else 
    { 
        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            new GoogleExternalLoginInfoProvider( 
                _appConfiguration["Authentication:Google:ClientId"], 
                _appConfiguration["Authentication:Google:ClientSecret"], 
                _appConfiguration["Authentication:Google:UserInfoEndpoint"] 
            ) 
        ); 
    } 
} 

if (bool.Parse(_appConfiguration["Authentication:Microsoft:IsEnabled"])) 
{ 
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"])) 
    { 
        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            IocManager.Resolve&lt;TenantBasedMicrosoftExternalLoginInfoProvider&gt;()); 
    } 
    else 
    { 
        externalAuthConfiguration.ExternalLoginInfoProviders.Add( 
            new MicrosoftExternalLoginInfoProvider( 
                _appConfiguration["Authentication:Microsoft:ConsumerKey"], 
                _appConfiguration["Authentication:Microsoft:ConsumerSecret"] 
            ) 
        ); 
    } 
} 

}

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

Hi,

We are already using app.UseStaticFiles() in our Startup file. However, after inspecting the browser's network section, we see the following:

/view-resources/Areas/App/Views/clients/index.js?v=ARUfqU9IfxpqYpruFCH0eHhwijWK7_D18dJI98XrYjE

To include JavaScript files in our HTML, we are using the following code:

@section Scripts { <script type="text/javascript" src="~/view-resources/Areas/App/Views/clients/index.js" asp-append-version="true"></script> }

Despite this, we still need to perform a hard refresh after every deployment for the latest changes to take effect, which we would like to avoid. Could you please advise on how to ensure the changes take effect without requiring a hard refresh?

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 

I added the logout URL on the auth0 application, but it didn't work

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.

It worked. Thanks.

But I noticed one thing, when I hitting the authorize URL directly in the browser it just ask me to enter email but with redirection through code its giving me additional option to continue with google which I don't need.

You can copy the code from API website to MVC

You mean I should copy the below section from CDPWebHostModule class to CDPWebMvcModule class

private void ConfigureExternalAuthProviders() { var externalAuthConfiguration = IocManager.Resolve<ExternalAuthConfiguration>();

if (bool.Parse(_appConfiguration["Authentication:OpenId:IsEnabled"]))
{
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"]))
    {
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            IocManager.Resolve&lt;TenantBasedOpenIdConnectExternalLoginInfoProvider&gt;());
    }
    else
    {
        var jsonClaimMappings = new List&lt;JsonClaimMap&gt;();
        _appConfiguration.GetSection("Authentication:OpenId:ClaimsMapping").Bind(jsonClaimMappings);

        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            new OpenIdConnectExternalLoginInfoProvider(
                _appConfiguration["Authentication:OpenId:ClientId"],
                _appConfiguration["Authentication:OpenId:ClientSecret"],
                _appConfiguration["Authentication:OpenId:Authority"],
                _appConfiguration["Authentication:OpenId:LoginUrl"],
                bool.Parse(_appConfiguration["Authentication:OpenId:ValidateIssuer"]),
                _appConfiguration["Authentication:OpenId:ResponseType"],
                jsonClaimMappings
            )
        );
    }
}

if (bool.Parse(_appConfiguration["Authentication:WsFederation:IsEnabled"]))
{
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"]))
    {
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            IocManager.Resolve&lt;TenantBasedWsFederationExternalLoginInfoProvider&gt;());
    }
    else
    {
        var jsonClaimMappings = new List&lt;JsonClaimMap&gt;();
        _appConfiguration.GetSection("Authentication:WsFederation:ClaimsMapping").Bind(jsonClaimMappings);

        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            new WsFederationExternalLoginInfoProvider(
                _appConfiguration["Authentication:WsFederation:ClientId"],
                _appConfiguration["Authentication:WsFederation:Tenant"],
                _appConfiguration["Authentication:WsFederation:MetaDataAddress"],
                _appConfiguration["Authentication:WsFederation:Authority"],
                jsonClaimMappings
            )
        );
    }
}

if (bool.Parse(_appConfiguration["Authentication:Facebook:IsEnabled"]))
{
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"]))
    {
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            IocManager.Resolve&lt;TenantBasedFacebookExternalLoginInfoProvider&gt;());
    }
    else
    {
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(new FacebookExternalLoginInfoProvider(
            _appConfiguration["Authentication:Facebook:AppId"],
            _appConfiguration["Authentication:Facebook:AppSecret"]
        ));
    }
}

if (bool.Parse(_appConfiguration["Authentication:Twitter:IsEnabled"]))
{
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"]))
    {
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            IocManager.Resolve&lt;TenantBasedTwitterExternalLoginInfoProvider&gt;());
    }
    else
    {
        var twitterExternalLoginInfoProvider = new TwitterExternalLoginInfoProvider(
            _appConfiguration["Authentication:Twitter:ConsumerKey"],
            _appConfiguration["Authentication:Twitter:ConsumerSecret"],
            _appConfiguration["App:ClientRootAddress"].EnsureEndsWith('/') + "account/login"
        );

        externalAuthConfiguration.ExternalLoginInfoProviders.Add(twitterExternalLoginInfoProvider);
    }
}

if (bool.Parse(_appConfiguration["Authentication:Google:IsEnabled"]))
{
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"]))
    {
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            IocManager.Resolve&lt;TenantBasedGoogleExternalLoginInfoProvider&gt;());
    }
    else
    {
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            new GoogleExternalLoginInfoProvider(
                _appConfiguration["Authentication:Google:ClientId"],
                _appConfiguration["Authentication:Google:ClientSecret"],
                _appConfiguration["Authentication:Google:UserInfoEndpoint"]
            )
        );
    }
}

if (bool.Parse(_appConfiguration["Authentication:Microsoft:IsEnabled"]))
{
    if (bool.Parse(_appConfiguration["Authentication:AllowSocialLoginSettingsPerTenant"]))
    {
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            IocManager.Resolve&lt;TenantBasedMicrosoftExternalLoginInfoProvider&gt;());
    }
    else
    {
        externalAuthConfiguration.ExternalLoginInfoProviders.Add(
            new MicrosoftExternalLoginInfoProvider(
                _appConfiguration["Authentication:Microsoft:ConsumerKey"],
                _appConfiguration["Authentication:Microsoft:ConsumerSecret"]
            )
        );
    }
}

}

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

Then which API can I use for my mobile app to provide them response with asp dot net access token details when they send me the auth0 token or id token. Do I need to build a custom API?

Hi,

Is there a generic way or some configuration we need to do to apply versioning to JavaScript files?

Currently, we are using asp-append-version="true" when including JavaScript files in our HTML, as shown below but it is not working:

@section Scripts { <script type="text/javascript" src="~/view-resources/Areas/App/Views/clients/index.js" asp-append-version="true"></script> } Looking forward to guidance on resolving this issue.

hi

I also want to pass a 'organization' parameter.

You can add your custom logic by options.Events.OnRedirectToIdentityProvider method.

context.ProtocolMessage.SetParameter("connection", "sms");

authenticationBuilder.AddOpenIdConnect(options => 
{ 
    options.ClientId = configuration["Authentication:OpenId:ClientId"]; 
    options.Authority = configuration["Authentication:OpenId:Authority"]; 
    options.SignedOutRedirectUri = configuration["App:WebSiteRootAddress"] + "Account/Logout"; 
    options.ResponseType = configuration["Authentication:OpenId:ResponseType"]; 
 
    options.TokenValidationParameters = new TokenValidationParameters() 
    { 
        ValidateIssuer = bool.Parse(configuration["Authentication:OpenId:ValidateIssuer"]) 
    }; 
 
    options.Events.OnTokenValidated = context => 
    { 
        var jsonClaimMappings = new List<JsonClaimMap>(); 
        configuration.GetSection("Authentication:OpenId:ClaimsMapping").Bind(jsonClaimMappings); 
 
        context.AddMappedClaims(jsonClaimMappings); 
 
        return Task.FromResult(0); 
    }; 
 
    var clientSecret = configuration["Authentication:OpenId:ClientSecret"]; 
    if (!clientSecret.IsNullOrEmpty()) 
    { 
        options.ClientSecret = clientSecret; 
    } 
 
    options.Events.OnRedirectToIdentityProvider = context => 
    { 
        if (true) 
        { 
            context.ProtocolMessage.SetParameter("connection", "sms"); 
        } 
 
        return Task.FromResult(0); 
    }; 
}); 

I got that, but it will based on user selection that whether he wants to login through email or sms. So it should be passed from account/login.cshtml page. But how can I pass that in authconfigure class and MyOpenIdChallengeResult class where I am setting up the options

hi

The actual exception is - Unknown external auth provider: OpenIdConnect.

Please share full error logs.

Thanks.

Is below is something you are asking for?

{"ClassName":"System.Exception","Message":"Unknown external auth provider: OpenIdConnect","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at Abp.AspNetZeroCore.Web.Authentication.External.ExternalAuthManager.CreateProviderApi(String provider)\r\n at Abp.AspNetZeroCore.Web.Authentication.External.ExternalAuthManager.GetUserInfo(String provider, String accessCode)\r\n at CDP.Web.Controllers.TokenAuthController.GetExternalUserInfo(ExternalAuthenticateModel model) in D:\Dimple Khathuria\CDP 13.0\src\CDP.Web.Core\Controllers\TokenAuthController.cs:line 673","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233088,"Source":"Abp.AspNetZeroCore.Web","WatsonBuckets":null}

Showing 1 to 10 of 219 entries