Let me share you my complete scenario. I have a multi tenant application. I want to enable both okta and auth0 for each tenant. As asp.net zero support only one authentication for a single tenant, I understand I need to customize the code. For this I will create a entity which will have configuration details like client id, secret etc. tenant wise for different providers.
I have enabled AllowSocialLoginSettingsPerTenant in appsettings and setup OpenId with default values. Now when ExternalLogin function gets called in Account controller on openidconnect login button, I believe it gets the default set values.public ActionResult ExternalLogin(string provider, string returnUrl, string ss = "") { var redirectUrl = Url.Action( "ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl, authSchema = provider, ss = ss }); var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); return Challenge(properties, provider); }
But here I want to get the custom configuration for a tenant either for auth0 or okta and accordingly redirect at runtime.
Could you please help me with the custom code I need to place in ExternalLogin function.
After seeing the source commit you shared, I updated my code as it is. But when trying to dynamically updating on externallogin function it didn't work. Below is the code
[HttpPost]
public ActionResult ExternalLogin(string provider, string returnUrl, string ss = "")
{
using (_openIdConnectOptions.As<TenantBasedOpenIdConnectOptions>().Change(new OpenIdConnectOptions {
ClientId = "xxxxxxxxxxxxxxxxxxx",
ClientSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
Authority = "https://dev-76726332.okta.com/oauth2/default",
ResponseType = "code",
Scope = { "openid", "profile", "email" }
}))
{
var redirectUrl = Url.Action(
"ExternalLoginCallback",
"Account",
new
{
ReturnUrl = returnUrl,
authSchema = provider,
ss = ss
});
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return Challenge(properties, provider);
}
}
Could you please help me to figure this out that where and how can change the options?
Also could you please explain what exactly the changes in the source means
Let me share you my complete scenario. I have a multi tenant application. I want to enable both okta and auth0 for each tenant. As asp.net zero support only one authentication for a single tenant, I understand I need to customize the code. For this I will create a entity which will have configuration details like client id, secret etc. tenant wise for different providers. I have enabled AllowSocialLoginSettingsPerTenant in appsettings and setup OpenId with default values. Now when ExternalLogin function gets called in Account controller on openidconnect login button, I believe it gets the default set values.
public ActionResult ExternalLogin(string provider, string returnUrl, string ss = "")
{
var redirectUrl = Url.Action(
"ExternalLoginCallback",
"Account",
new
{
ReturnUrl = returnUrl,
authSchema = provider,
ss = ss
});
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return Challenge(properties, provider);
}
But here I want to get the custom configuration for a tenant either for auth0 or okta and accordingly redirect at runtime.
Could you please help me with the custom code I need to place in ExternalLogin function.
hi
Yes, See https://github.com/aspnetzero/aspnet-zero-core/commit/7541fa92769e0ff340ccfb9424a5f58c62ca1c08
I create a ExternalLoginCustom method in Account controller.
In this function I wrote
using (_openIdConnectOptions.As<TenantBasedOpenIdConnectOptions>().Change(new OpenIdConnectOptions()))
{
}
First it says TenantBasedOpenIdConnectOptions does contain a function Change. Also the link you have shared has expired I believe, its not working.
Also how should I set the optons in the using block.
Hi @kansoftware
Sorry for our late reply. When you get a token from Okta from your mobile app, you can use https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Core/Controllers/TokenAuthController.cs#L549 endpoint on AspNet Zero side.
The link is not working
Unfortunately, we can’t share the entire codebase, but we’d be glad to provide any specific files or sections you require. Please let us know which files or areas you need access to, and we’ll make sure to share them promptly.
Hi,
Could you try using per request redis cache and see if it makes any difference ? https://aspnetboilerplate.com/Pages/Documents/PerRequestRedisCache
What about the custom configuration I want to apply when creating a connection with Redis?
I am using ABP version 13.0.0. I have enabled Redis cache in the application through the appsettings file. Redis is connected and working in the application.
However, I am facing two issues:-
I found a solution for the timeout issue, but I am unable to configure it in the ASP.NET Zero application due to its inbuilt code.
Here is the ASP.NET Zero code used to connect to Redis:
Link : "https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.RedisCache/Runtime/Caching/Redis/AbpRedisCacheDatabaseProvider.cs"
private ConnectionMultiplexer CreateConnectionMultiplexer() { return ConnectionMultiplexer.Connect(_options.ConnectionString); }
The solution I found is as follows:
var configurationOptions = new ConfigurationOptions { EndPoints = { RedisConnectionString }, Ssl = true, ConnectTimeout = 30000, // Increase timeout SyncTimeout = 30000, // Increase sync timeout ConnectRetry = 5, // Number of times to retry connecting ReconnectRetryPolicy = new ExponentialRetry(5000), // Exponential backoff policy KeepAlive = 30 }; return ConnectionMultiplexer.Connect(configurationOptions);
After implementing this solution, I did not face any RedisTimeoutException issues in my other custom applications.
However, I am still facing slowness in the entire application when Redis is used.
So, please provide both solution and customization as soon as possible.
Hi @kansoftware,
You can follow the steps used in Angular for updating the profile picture to implement the same functionality. However, for the mobile side, I recommend researching resources on MAUI file uploading for handling file uploads. If you’d like, I can create an issue for this feature in the next release.
Hi, Our mobile app is in ionic. We are using 13.0.0 version of dot net. Are you saying we need customize the code for mobile app? Or there is inbuilt functionality? Can you please provide me a documentation for that
Thanks
I can see that the functionality for updating the profile picture is built-in. To update the profile picture, the UpdateProfilePicture function is used, which is part of the Profile App Service. To fetch the profile picture, the GetProfilePicture function is used, which is part of the Profile Controller. This works on our web application.
How can we use the same functionality for our mobile application, and what changes do we need to make?
Can I call these function on login button in Account controller to set options at runtime? If yes then how