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?
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
Can I call these function on login button in Account controller to set options at runtime? If yes then how
UserLoginInfo
Sorry, I didn't understand. What do you mean can you please describe. I am getting the error from var externalUser = await GetExternalUserInfo(model); And after going to internal function the actual error comes from the below method
public IDisposableDependencyObjectWrapper<IExternalAuthProviderApi> CreateProviderApi(string provider)
{
ExternalLoginProviderInfo externalLoginProviderInfo = ((!_externalAuthConfiguration.ExternalLoginInfoProviders.Any((IExternalLoginInfoProvider infoProvider) => infoProvider.Name == provider)) ? _externalAuthConfiguration.Providers.FirstOrDefault((ExternalLoginProviderInfo p) => p.Name == provider) : _externalAuthConfiguration.ExternalLoginInfoProviders.Single((IExternalLoginInfoProvider infoProvider) => infoProvider.Name == provider).GetExternalLoginInfo());
if (externalLoginProviderInfo == null)
{
throw new Exception("Unknown external auth provider: " + provider);
}
IDisposableDependencyObjectWrapper<IExternalAuthProviderApi> disposableDependencyObjectWrapper = _iocResolver.ResolveAsDisposable<IExternalAuthProviderApi>(externalLoginProviderInfo.ProviderApiType);
disposableDependencyObjectWrapper.Object.Initialize(externalLoginProviderInfo);
return disposableDependencyObjectWrapper;
}
I want to set OpenIdConnectOptions during runtime for tenant. Is it possible if yes then how?