Hi liangshiwei, Thanks for your support!
Hi liangshiwei, If I write the example code exactly as below, it creates a user in the AbpUsers table. If I log in again with the same user through an external provider, this time the CreateExternalUserAsync method is not triggered. Your suggestion works and is effective, but it means that the method (CreateExternalUserAsync) will always check whether the user exists before being called
[ExposeServices(typeof(LoginModel))]
public class MyLoginModel : LoginModel
{
protected virtual async Task<IdentityUser> CreateExternalUserAsync(ExternalLoginInfo info)
{
var user = await base.CreateExternalUserAsync(info);
}
}
adding external Login provider :
private void ConfigureExternalProviders(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddAuthentication()
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://localhost:44366/";
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]); ;
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.ClientId = "Client1";
options.ClientSecret = "mysecret";
options.UsePkce = true;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("role");
options.Scope.Add("email");
options.Scope.Add("phone");
options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "sub");
}
);
Hi Liangshiwei,
Thank you for your response, I appreciate your answer and I understand it very well. However, it seems like a workaround solution. I want to override the place where the decision to trigger this method is made. Even if I override the CreateExternalUserAsync method, it will still attempt to find the user every time and not be able to find it
Hi, After a successful login from an external login provider, I want to manually check whether the user exists in my system and then when I find the appropriate user, log them into my system (especially for tenant users)
Note : External login provider is an another Abp project
I want the logged-in and deactivated user to be unable to perform any actions in the application or to force log out when they click anywhere. Is there a way to achieve this?
As expressed by the user @mgurer , the methods of the class we implemented from IAbpClaimsPrincipalContributor are not being triggered in the refresh token flow. Therefore, we created a class derived from MyPrepareAccessTokenPrincipal. However, within the HandleAsync, how can we use our repository class?
public ValueTask HandleAsync(OpenIddictServerEvents.ProcessSignInContext context)
{
var identity = context.AccessTokenPrincipal?.Identities.FirstOrDefault();
var userId = identity?.FindUserId();
if (userId!=null)
{
var user = userRepository.GetAsync(userId); //<-- HOW CAN I INJECT userRepository
}
return default;
}
Hello Anjali_Musmade,
Thank you for your response. It was definitely helpful to see this question. However, if possible, resolving the issue at its source is always a better solution. I'm curious about the following:
Would using ArgumentException instead of BusinessException in the Check class called within the Entity be a preference or a necessity? Because before .NET 7, we couldn't perform dependency injection into entity classes. Therefore, was it a necessity to use exceptions of type ArgumentException in entity classes due to the inability to localize them, or was it a deliberate choice?
About 10 months ago, Halil İbrahim Kalkan published an impressive article. I would like to see the adaptation of the Abp Suite's entity and manager classes in accordance with this article.
When I create an entity with Abp Suite, I notice that some length and not-null checks are being performed.
If you agree with what I've mentioned in both points, Abp Suite should generate more robust code and I expect a change in this regard.
Hi @maliming,
The code you provided worked, thank you very much for your support