Hi
currently app.component.ts is the bootstraped component https://angular.io/guide/bootstrapping so if you place any api call in there it will be called so you have to use conditional operator there to calling api when the state is not authenticated.
if (this.configStateService.getDeep('currentUser.isAuthenticated')) {
//authenticated code here
}
you don't have to place these if conditions
in any component if you have used authguard in the routing. so you have to put this if condition
only on app.component.ts.
Hello LinchArnold,
You can download the source code of @volo/abp.commercial.ng.ui
with the following command
abp add-package @volo/abp.commercial.ng.ui --with-source-code
Please do let me know if this helps you.
Thank you, Anjali
Hello abpnewtonvisionco,
Apologies for the delay in response. We are still working on your query and shall get back to you as soon as possible.
Regards, Anjali
Hello alexander.nikonov,
I have looked into your code provided above. I will suggest to add ngOnDestroy
method to call this.unsubscriber$.next();
and this.unsubscriber$.complete();
just like in below code.
Please check with this code if find helpful.
this.oAuthService.events
.pipe(
takeUntil(this.unsubscriber$), // add this line also
)
.subscribe(event => {
if (event?.type === 'logout') {
console.log('Logout event received');
this.unsubscriber$.next();
}
});
ngOnDestroy() {
this.unsubscriber$.next();
this.unsubscriber$.complete();
}
Please do let us know if anything else needed.
Thank you, Anjali
Hi
Now after logout i guess your api will also not get called, can you check please?
Hi
i didn't do any changes suggested on this ticket https://support.abp.io/QA/Questions/5253/Token--Authentication. here is the code that i have only added to abp io new mvc template
added https://localhost:44350/signin-oidc as redirecturi in AzureAd App
Step 2 Changes in Pages/Account/Login.cshtml (note you have to create the Login.cshtm file and Account folder manually)
Login.cshtml.cs code
using Jupiter.Web;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Owl.reCAPTCHA;
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Account.ExternalProviders;
using Volo.Abp.Account.Public.Web;
using Volo.Abp.Account.Public.Web.Pages.Account;
using Volo.Abp.Account.Security.Recaptcha;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Security.Claims;
namespace Jupiter.Web.Pages.Account
{
[ExposeServices(typeof(LoginModel))]
[Dependency(ReplaceServices = true)]
public class AppLoginModel : LoginModel
{
private readonly IConfiguration _configuration;
public AppLoginModel(IAuthenticationSchemeProvider schemeProvider, IOptions< AbpAccountOptions > accountOptions, IAbpRecaptchaValidatorFactory recaptchaValidatorFactory, IAccountExternalProviderAppService accountExternalProviderAppService, ICurrentPrincipalAccessor currentPrincipalAccessor, IOptions< IdentityOptions > identityOptions, IOptionsSnapshot< reCAPTCHAOptions > reCaptchaOptions, IConfiguration configuration) : base(schemeProvider, accountOptions, recaptchaValidatorFactory, accountExternalProviderAppService, currentPrincipalAccessor, identityOptions, reCaptchaOptions)
{
_configuration = configuration;
}
public override async Task< IActionResult > OnGetExternalLoginCallbackAsync(string returnUrl = "", string returnUrlHash = "", string remoteError = null)
{
var token = await SignInManager.GetExternalLoginInfoAsync();
var accessToken = token?.AuthenticationTokens?.FirstOrDefault(x => x.Name == "access_token");
var powerbi = new PowerBiServiceApi(_configuration, accessToken?.Value ?? string.Empty);
HttpContext.Response.Cookies.Append("AuthToken", accessToken?.Value ?? string.Empty);
var report = await powerbi.GetReport(Guid.Parse("workspaceid"), Guid.Parse("reportid"));
return await base.OnGetExternalLoginCallbackAsync(returnUrl, returnUrlHash, remoteError);
}
}
}
Here is the code for PowerBiServiceApi
using Microsoft.PowerBI.Api;
using Microsoft.Rest;
using System.Threading.Tasks;
using System;
using Microsoft.Extensions.Configuration;
namespace Jupiter.Web
{
public class EmbeddedReportViewModel
{
public string Id;
public string Name;
public string EmbedUrl;
public string Token;
}
public class PowerBiServiceApi
{
private string urlPowerBiServiceApiRoot { get; }
private string AccessToken { get; }
public PowerBiServiceApi(IConfiguration configuration, string accessToken)
{
this.urlPowerBiServiceApiRoot = configuration["PowerBi:ServiceRootUrl"];
AccessToken = accessToken;
}
public static readonly string[] RequiredScopes = new string[] {
"https://analysis.windows.net/powerbi/api/Report.Read.All"
};
public PowerBIClient GetPowerBiClient()
{
var tokenCredentials = new TokenCredentials(AccessToken, "Bearer");
return new PowerBIClient(new Uri(urlPowerBiServiceApiRoot), tokenCredentials);
}
public async Task<EmbeddedReportViewModel> GetReport(Guid WorkspaceId, Guid ReportId)
{
PowerBIClient pbiClient = GetPowerBiClient();
// Call the Power BI Service API to get embedding data
var report = await pbiClient.Reports.GetReportInGroupAsync(WorkspaceId, ReportId);
// Return report embedding data to caller
return new EmbeddedReportViewModel
{
Id = report.Id.ToString(),
EmbedUrl = report.EmbedUrl,
Name = report.Name,
Token = AccessToken
};
}
}
}
Note i have save the azure ad access token to Cookies so you can access the token to make call while getting reports and workspace.
do let me know if this doesn't work.
Hello alexander.nikonov,
Thank you for the update and apologies for the inconvenience.
We understand your problem and looking for better solution, please allow us sometime to get back on the same.
Thank You. Anjali