Base solution for your next web application
Open Closed

Impersonation working locally but after the deployment to Azure this functionality is not working #9761


User avatar
0
omkarchoudhari created

ANZ Template version 9.0 (Angular+.NetCore) Code base

Details:

Impersonate Error: Login As this User - Redirect to login page. User impersonation as the tenant does not allow to impersonate login "Login As this User." Action always redirects to Login page with tenant selected.

The Aplication is hosted in Azure web app service(Linux). From website log we are not getting any much informative error seems impersonate URL returns 302 error.

Urgent help needed !


11 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    hi omkarchoudhari

    Could you share your website url to me(include user&password)? [email protected]

    From website log we are not getting any much informative error seems impersonate URL returns 302 error.

    Please share these logs

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @

    The default timeout for an impersonationToken is 1 min. It seems like the request on Azure takes more than 1 min. Could you increase this timeout here https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Authorization/Impersonation/ImpersonationManager.cs#L137 and try again ?

    Thanks,

  • User Avatar
    0
    omkarchoudhari created

    We tried doing this but it is not working. Can you suggest some solution or workaround for the same ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @omkarchoudhari

    1. Is your app running as just 1 instance or is it more than 1 ?
    2. Do you use Redis cache ?
  • User Avatar
    0
    omkarchoudhari created
    1. Our app is running just one instance on Azure web app service (Linux machine)
    2. We are not using redis cache
    3. Even after making the TimeoutPeriod as 10 mins. Impersonation redirects back to login page
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @omkarchoudhari

    Sorry for my late reply. I missed your question somehow. Did you find a solution to this problem ?

  • User Avatar
    0
    omkarchoudhari created

    Hello @ismcagdas

    NO. We are still struggling with this issue and client has raised this from time to time. Can you look at this issue please ? Maybe look at issue remotely via zoom ?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @omkarchoudhari

    Sure, please send an email to [email protected] and we will arrange a Zoom meeting.

    Thanks,

  • User Avatar
    0
    ashjackson created

    Hi There,

    I am having this issue as well, in dev imperonsation works, but in live i get a 500.

    I've dug in the log and it appears to be a problem with CORS

    2021-02-02 12:40:00.657 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request starting HTTP/1.1 OPTIONS https://my.api.url/api/TokenAuth/ImpersonatedAuthenticate?impersonationToken=adf9571e-2776-472f-a2dc-273e7842df87&d=1612269598634 - 0
    2021-02-02 12:40:00.657 +00:00 [Debug] Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: OPTIONS requests are not supported
    2021-02-02 12:40:00.657 +00:00 [Debug] Microsoft.AspNetCore.Routing.Matching.DfaMatcher: 1 candidate(s) found for the request path '/api/TokenAuth/ImpersonatedAuthenticate'
    2021-02-02 12:40:00.657 +00:00 [Debug] Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: Request matched endpoint '405 HTTP Method Not Supported'
    2021-02-02 12:40:00.657 +00:00 [Debug] Microsoft.AspNetCore.Cors.Infrastructure.CorsService: The request has an origin header: 'https://my.angular.url'.
    2021-02-02 12:40:00.657 +00:00 [Information] Microsoft.AspNetCore.Cors.Infrastructure.CorsService: CORS policy execution successful.
    2021-02-02 12:40:00.657 +00:00 [Debug] Microsoft.AspNetCore.Cors.Infrastructure.CorsService: The request is a preflight request.
    2021-02-02 12:40:00.657 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request finished HTTP/1.1 OPTIONS https://my.api.url/api/TokenAuth/ImpersonatedAuthenticate?impersonationToken=adf9571e-2776-472f-a2dc-273e7842df87&d=1612269598634 - 0 - 204 - - 0.3916ms
    2021-02-02 12:40:00.694 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request starting HTTP/1.1 POST https://my.api.url/api/TokenAuth/ImpersonatedAuthenticate?impersonationToken=adf9571e-2776-472f-a2dc-273e7842df87&d=1612269598634 application/json 0
    2021-02-02 12:40:00.694 +00:00 [Debug] Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: POST requests are not supported
    2021-02-02 12:40:00.694 +00:00 [Debug] Microsoft.AspNetCore.Routing.Matching.DfaMatcher: 1 candidate(s) found for the request path '/api/TokenAuth/ImpersonatedAuthenticate'
    2021-02-02 12:40:00.694 +00:00 [Debug] Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Endpoint 'MSystem.Web.Controllers.TokenAuthController.ImpersonatedAuthenticate (MSystem.Web.Core)' with route pattern 'api/TokenAuth/ImpersonatedAuthenticate' is valid for the request path '/api/TokenAuth/ImpersonatedAuthenticate'
    

    Can this be enabled by editing the web.config?

    Kind Regards, AJ.

  • User Avatar
    0
    omkarchoudhari created

    Hello @ismcagdas ,

    Any Update on this ? We are still unable to resolve this issue.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @omkarchoudhari

    We fixed this problem via email with one of your developers. Could you check it with your Team ?

    Hi @ashjackson

    Are there any error logs in the log file ? If you are getting a 500 error, there should be an error log. If not, could you change impersonation code on Angular app as below and try again ?

    impersonate(userId: number, tenantId?: number): void {
    
            const input = new ImpersonateInput();
            input.userId = userId;
            input.tenantId = tenantId;
    
            this._accountService.impersonate(input)
                .subscribe((result: ImpersonateOutput) => {
                    this._authService.logout(false);
    
                    let targetUrl = this._appUrlService.getAppRootUrlOfTenant(result.tenancyName) + 'index.html?impersonationToken=' + result.impersonationToken;
                    if (input.tenantId) {
                        targetUrl = targetUrl + '&tenantId=' + input.tenantId;
                    }
    
                    location.href = targetUrl;
                });
        }