Hello sanobarm@cloudassert.com,
Thank you for your confirmation. Closing the ticket.
Thank you, Anjali
Hi,
Can you share your PreConfigureService Code from HttpApiHostModule?
Hello alexander.nikonov,
After logout it will redirect to your landing page i.e. Home and if you are calling any api's inside home component which is not authorized then this 401 error occurs for that particular api's. For reproduce the same Issue I added 1 api in Home component. I am calling that api in ngOnInit ( initial method ) with login it is working fine. But if I logout then we are facing 401 status in network tab the reason is we are calling api's without authorized.
I tried with your code to call api's which is inside ngOnInitInner which was giving me error without if (this.authService.isAuthenticated) { }
block
please check the Initiator column for which api's you are getting 401 error and try to add those api calls inside this if (this.authService.isAuthenticated) { }
block
When I tried with if (this.authService.isAuthenticated) { }
block , that api will not get call and hence not get any error.
protected ngOnInitInner() {
if (this.authService.isAuthenticated) {
this.homeService.getNewsForHomePage()
.pipe(take(1))
.subscribe((newsResponse) => {... });
this.homeService.getUrlsForHomePage()
.pipe(take(1))
.subscribe((newsUrlParameterResponse) => {... });
}
}
If the value by authService.isAuthenticated
is not giving false
on logout then please try this
if (this.configStateService.getDeep('currentUser.isAuthenticated')) {}
please do let me know if it helps you,
Thank you, Anjali
Hello aksogut ,
Please check this document if found helpful for you
https://dev.iyzipay.com/en/api/installment-service
Thank you, Anjali
Hello darutter,
Please try with below example:-
I have created first Entity as Employee -> EmployeeName, Age Second Entity as Items -> ItemName, ItemInfo I have added Navigation (manytomany) from Employee to Items.
public class EmployeeExcelNewDto
{
public String EmplyeeName { get; set; }
public int Age { get; set; }
public String ItemName { get; set; }
}
EfCoreEmployeeRepository
protected virtual async Task<IQueryable<EmployeeWithNavigationProperties>> GetQueryForNavigationPropertiesAsync()
{
var dbContext = await GetDbContextAsync();
return from employee in (await GetDbSetAsync())
select new EmployeeWithNavigationProperties
{
Employee = employee,
Items = (from itm in dbContext.Items
join empitm in employee.Items on itm.Id equals empitm.ItemId
select itm).ToList()
};
}
EmployeesAppService
public virtual async Task<IRemoteStreamContent> GetListAsExcelFileAsync(EmployeeExcelDownloadDto input)
{
var downloadToken = await _excelDownloadTokenCache.GetAsync(input.DownloadToken);
if (downloadToken == null || input.DownloadToken != downloadToken.Token)
{
throw new AbpAuthorizationException("Invalid download token: " + input.DownloadToken);
}
var employees = await _employeeRepository.GetListWithNavigationPropertiesAsync(input.FilterText, input.EmployeeName, input.AgeMin, input.AgeMax);
var List = new List<EmployeeExcelNewDto>();
employees.ForEach(eitem =>
{
foreach (var i in eitem.Items)
{
var emp = new EmployeeExcelNewDto
{
EmplyeeName = eitem.Employee.EmployeeName,
Age = eitem.Employee.Age,
ItemName = i.ItemName
};
List.Add(emp);
};
});
var memoryStream = new MemoryStream();
await memoryStream.SaveAsAsync(List);
memoryStream.Seek(0, SeekOrigin.Begin);
return new RemoteStreamContent(memoryStream, "Employees.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
Output excel will be like
Please do let me know if this helps you,
Thank you, Anjali
Hello alexander.nikonov,
import { AuthService } from '@abp/ng.core';
constructor(private authService: AuthService)
ngOnInit()
{
if (this.authService.isAuthenticated) //like -> this.configStateService.getDeep('currentUser.isAuthenticated')
{
this.homeService.getNewsForHomePage()
this.homeService.getNewsForHomePage()
//other code and API which you are calling at initial...
}
}
Could you please try with this code
.pipe(filter(() => this.configStateService.getDeep('currentUser.isAuthenticated'))
This condition will not work as it's not authorized, so will not execute the next statement.
HomeComponent
get calls whether user logged in or not, so without get authorized it will give error.
please do let me know if this helps you.
Thank you, Anjali
Hi
i found that Microsoft.Identity.Web doesn't work with await SignInManager.GetExternalLoginInfoAsync();
so that's why you are not able to proceed with login.
I tried with <PackageReference Include="Microsoft.Graph" Version="5.25.0" />
i am able get GraphServiceClient
working
by creating a IAccessTokenProvider
implementation
creaate a IntegratedAbpioTokenProvider
like below in authservermodule
using Microsoft.AspNetCore.Identity;
using Microsoft.Kiota.Abstractions.Authentication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Acme.BookStore
{
public class IntegratedAbpioTokenProvider : IAccessTokenProvider
{
public IntegratedAbpioTokenProvider(SignInManager< Volo.Abp.Identity.IdentityUser > signInManager)
{
SignInManager = signInManager ?? throw new Exception();
}
public SignInManager< Volo.Abp.Identity.IdentityUser > SignInManager { get; set; }
public AllowedHostsValidator AllowedHostsValidator { get; }
public async Task< string > GetAuthorizationTokenAsync(Uri uri, Dictionary<string, object>? additionalAuthenticationContext = null, CancellationToken cancellationToken = default)
{
var token = await SignInManager.GetExternalLoginInfoAsync();
var accessToken = token?.AuthenticationTokens?.FirstOrDefault(x => x.Name == "access_token");
return accessToken?.Value ?? string.Empty;
}
}
}
and you can initialize GraphServiceClient
like this
if you still want to go with identity web please follow this github example
https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/2-WebApp-graph-user/2-1-Call-MSGraph
you just have to add following code
context.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(configuration.GetSection("AzureAd"), displayName: "Webapp")
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddMicrosoftGraph(configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
but after doing that you have to create a user inside OnGetExternalLoginCallbackAsync
please see the full implementation of OnGetExternalLoginCallbackAsync
https://github.com/abpframework/abp/blob/3fb86d658981748289ba8b6d5c59e857bc8c9e18/modules/account/src/Volo.Abp.Account.Web/Pages/Account/Login.cshtml.cs#L175 which you have to modify it based on Microsoft.Identity.Web
results.
SigninManager docs on microsoft https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.identity.signinmanager-1.getexternallogininfoasync?view=aspnetcore-7.0
Hello sanobarm@cloudassert.com,
Please do let us know if this solution has worked for you?
Awaiting for your response.
Thank You, Anjali
Hello nanohealthserviceaccount,
Please do let us know if this solution has worked for you?
Awaiting for your response.
Thank You, Anjali
Hello bkrm.dev01,
Please do let us know if we can help you with something else?
Thank You, Anjali