Angular - AuthGuard is redirecting Iframe











up vote
1
down vote

favorite












I am implementing an iFrame in my angular application. When i am giving the src url directly in the html, the app is working fine and loading the requested UI. But when i am fetching the src url from backend and passing it as a variable auth guard is redirecting the url to login page. How to fix this?



DefectsManagementComponent.html:



<div class="container-fluid dtep-style dtep-min-height-569px-minus-56px">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group"></div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<iframe id="defects" class="col-lg-12 col-md-12 col-sm-12 col-xs-12" title="Defects Management" src="url">
</iframe>
</div>
</div>
</div>
</div>


DefectsManagementComponent.ts:



export class DefectsManagementComponent implements OnInit {

url: string;

constructor(private service: SolutionInstanceService) {
}

ngOnInit() {
this.service.fetchSolutionByName("DEFECT_MANAGEMENT").subscribe(data =>{
this.url = data["solutionURL"];
});
}

}


AppRoutingModule.ts:



   const routes: Routes = [
{
path: "login",
component: LoginComponent
},
{
path: "home",
canActivate: [AuthGuardGuard],
component: HomeComponent
},
{
path: "defects",
component: DefectsManagementComponent
},
{
path: "",
redirectTo: "login",
pathMatch: "full"
},
{
path: "**",
redirectTo: "login",
pathMatch: "full"
}
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule









share|improve this question
























  • can you try with src in square brackets? ( [src]="url" )
    – Andrei Dumitrescu-Tudor
    Nov 19 at 7:12










  • i tried but still same result.
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:26










  • try console logging url after it has been set, to see if it is the correct value. If that is the return of an http call, you might need to call result on it.
    – Andrei Dumitrescu-Tudor
    Nov 19 at 7:30










  • I have logged it, the value is being fetched but when i am inspecting, it is showing the value of src as null in the source code.
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:31












  • Most of the times it is trying to access "http:localhost:4200/url" When i am giving src="url", it is accessing "http:localhost:4200/url" and when i change it to [src]="url", the url value is null
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:39

















up vote
1
down vote

favorite












I am implementing an iFrame in my angular application. When i am giving the src url directly in the html, the app is working fine and loading the requested UI. But when i am fetching the src url from backend and passing it as a variable auth guard is redirecting the url to login page. How to fix this?



DefectsManagementComponent.html:



<div class="container-fluid dtep-style dtep-min-height-569px-minus-56px">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group"></div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<iframe id="defects" class="col-lg-12 col-md-12 col-sm-12 col-xs-12" title="Defects Management" src="url">
</iframe>
</div>
</div>
</div>
</div>


DefectsManagementComponent.ts:



export class DefectsManagementComponent implements OnInit {

url: string;

constructor(private service: SolutionInstanceService) {
}

ngOnInit() {
this.service.fetchSolutionByName("DEFECT_MANAGEMENT").subscribe(data =>{
this.url = data["solutionURL"];
});
}

}


AppRoutingModule.ts:



   const routes: Routes = [
{
path: "login",
component: LoginComponent
},
{
path: "home",
canActivate: [AuthGuardGuard],
component: HomeComponent
},
{
path: "defects",
component: DefectsManagementComponent
},
{
path: "",
redirectTo: "login",
pathMatch: "full"
},
{
path: "**",
redirectTo: "login",
pathMatch: "full"
}
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule









share|improve this question
























  • can you try with src in square brackets? ( [src]="url" )
    – Andrei Dumitrescu-Tudor
    Nov 19 at 7:12










  • i tried but still same result.
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:26










  • try console logging url after it has been set, to see if it is the correct value. If that is the return of an http call, you might need to call result on it.
    – Andrei Dumitrescu-Tudor
    Nov 19 at 7:30










  • I have logged it, the value is being fetched but when i am inspecting, it is showing the value of src as null in the source code.
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:31












  • Most of the times it is trying to access "http:localhost:4200/url" When i am giving src="url", it is accessing "http:localhost:4200/url" and when i change it to [src]="url", the url value is null
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:39















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am implementing an iFrame in my angular application. When i am giving the src url directly in the html, the app is working fine and loading the requested UI. But when i am fetching the src url from backend and passing it as a variable auth guard is redirecting the url to login page. How to fix this?



DefectsManagementComponent.html:



<div class="container-fluid dtep-style dtep-min-height-569px-minus-56px">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group"></div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<iframe id="defects" class="col-lg-12 col-md-12 col-sm-12 col-xs-12" title="Defects Management" src="url">
</iframe>
</div>
</div>
</div>
</div>


DefectsManagementComponent.ts:



export class DefectsManagementComponent implements OnInit {

url: string;

constructor(private service: SolutionInstanceService) {
}

ngOnInit() {
this.service.fetchSolutionByName("DEFECT_MANAGEMENT").subscribe(data =>{
this.url = data["solutionURL"];
});
}

}


AppRoutingModule.ts:



   const routes: Routes = [
{
path: "login",
component: LoginComponent
},
{
path: "home",
canActivate: [AuthGuardGuard],
component: HomeComponent
},
{
path: "defects",
component: DefectsManagementComponent
},
{
path: "",
redirectTo: "login",
pathMatch: "full"
},
{
path: "**",
redirectTo: "login",
pathMatch: "full"
}
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule









share|improve this question















I am implementing an iFrame in my angular application. When i am giving the src url directly in the html, the app is working fine and loading the requested UI. But when i am fetching the src url from backend and passing it as a variable auth guard is redirecting the url to login page. How to fix this?



DefectsManagementComponent.html:



<div class="container-fluid dtep-style dtep-min-height-569px-minus-56px">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group"></div>
</div>
</div>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<iframe id="defects" class="col-lg-12 col-md-12 col-sm-12 col-xs-12" title="Defects Management" src="url">
</iframe>
</div>
</div>
</div>
</div>


DefectsManagementComponent.ts:



export class DefectsManagementComponent implements OnInit {

url: string;

constructor(private service: SolutionInstanceService) {
}

ngOnInit() {
this.service.fetchSolutionByName("DEFECT_MANAGEMENT").subscribe(data =>{
this.url = data["solutionURL"];
});
}

}


AppRoutingModule.ts:



   const routes: Routes = [
{
path: "login",
component: LoginComponent
},
{
path: "home",
canActivate: [AuthGuardGuard],
component: HomeComponent
},
{
path: "defects",
component: DefectsManagementComponent
},
{
path: "",
redirectTo: "login",
pathMatch: "full"
},
{
path: "**",
redirectTo: "login",
pathMatch: "full"
}
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule






angular iframe auth-guard






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 7:23









Iman

5011




5011










asked Nov 19 at 7:07









Yerramsetty G D SuryaPrakash

145




145












  • can you try with src in square brackets? ( [src]="url" )
    – Andrei Dumitrescu-Tudor
    Nov 19 at 7:12










  • i tried but still same result.
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:26










  • try console logging url after it has been set, to see if it is the correct value. If that is the return of an http call, you might need to call result on it.
    – Andrei Dumitrescu-Tudor
    Nov 19 at 7:30










  • I have logged it, the value is being fetched but when i am inspecting, it is showing the value of src as null in the source code.
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:31












  • Most of the times it is trying to access "http:localhost:4200/url" When i am giving src="url", it is accessing "http:localhost:4200/url" and when i change it to [src]="url", the url value is null
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:39




















  • can you try with src in square brackets? ( [src]="url" )
    – Andrei Dumitrescu-Tudor
    Nov 19 at 7:12










  • i tried but still same result.
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:26










  • try console logging url after it has been set, to see if it is the correct value. If that is the return of an http call, you might need to call result on it.
    – Andrei Dumitrescu-Tudor
    Nov 19 at 7:30










  • I have logged it, the value is being fetched but when i am inspecting, it is showing the value of src as null in the source code.
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:31












  • Most of the times it is trying to access "http:localhost:4200/url" When i am giving src="url", it is accessing "http:localhost:4200/url" and when i change it to [src]="url", the url value is null
    – Yerramsetty G D SuryaPrakash
    Nov 19 at 7:39


















can you try with src in square brackets? ( [src]="url" )
– Andrei Dumitrescu-Tudor
Nov 19 at 7:12




can you try with src in square brackets? ( [src]="url" )
– Andrei Dumitrescu-Tudor
Nov 19 at 7:12












i tried but still same result.
– Yerramsetty G D SuryaPrakash
Nov 19 at 7:26




i tried but still same result.
– Yerramsetty G D SuryaPrakash
Nov 19 at 7:26












try console logging url after it has been set, to see if it is the correct value. If that is the return of an http call, you might need to call result on it.
– Andrei Dumitrescu-Tudor
Nov 19 at 7:30




try console logging url after it has been set, to see if it is the correct value. If that is the return of an http call, you might need to call result on it.
– Andrei Dumitrescu-Tudor
Nov 19 at 7:30












I have logged it, the value is being fetched but when i am inspecting, it is showing the value of src as null in the source code.
– Yerramsetty G D SuryaPrakash
Nov 19 at 7:31






I have logged it, the value is being fetched but when i am inspecting, it is showing the value of src as null in the source code.
– Yerramsetty G D SuryaPrakash
Nov 19 at 7:31














Most of the times it is trying to access "http:localhost:4200/url" When i am giving src="url", it is accessing "http:localhost:4200/url" and when i change it to [src]="url", the url value is null
– Yerramsetty G D SuryaPrakash
Nov 19 at 7:39






Most of the times it is trying to access "http:localhost:4200/url" When i am giving src="url", it is accessing "http:localhost:4200/url" and when i change it to [src]="url", the url value is null
– Yerramsetty G D SuryaPrakash
Nov 19 at 7:39














1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










You should use square brackets around src to bind the value of url to it, otherwise you are assigning the string “url” to src. Also use ngIf on the iframe to only show it when url is populated. You then need to sanitize the url. See more at https://stackoverflow.com/a/38269951/10632970 .






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369811%2fangular-authguard-is-redirecting-iframe%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    You should use square brackets around src to bind the value of url to it, otherwise you are assigning the string “url” to src. Also use ngIf on the iframe to only show it when url is populated. You then need to sanitize the url. See more at https://stackoverflow.com/a/38269951/10632970 .






    share|improve this answer

























      up vote
      2
      down vote



      accepted










      You should use square brackets around src to bind the value of url to it, otherwise you are assigning the string “url” to src. Also use ngIf on the iframe to only show it when url is populated. You then need to sanitize the url. See more at https://stackoverflow.com/a/38269951/10632970 .






      share|improve this answer























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        You should use square brackets around src to bind the value of url to it, otherwise you are assigning the string “url” to src. Also use ngIf on the iframe to only show it when url is populated. You then need to sanitize the url. See more at https://stackoverflow.com/a/38269951/10632970 .






        share|improve this answer












        You should use square brackets around src to bind the value of url to it, otherwise you are assigning the string “url” to src. Also use ngIf on the iframe to only show it when url is populated. You then need to sanitize the url. See more at https://stackoverflow.com/a/38269951/10632970 .







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 8:29









        Andrei Dumitrescu-Tudor

        1798




        1798






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369811%2fangular-authguard-is-redirecting-iframe%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Create new schema in PostgreSQL using DBeaver

            Deepest pit of an array with Javascript: test on Codility

            Costa Masnaga