0

Tried to pass dynamic params (e.g. user token) from Angular app to Android app, works fine with static query params, but link is not opened with dynamic ones...

Link is opened:

<a href="intent://dummyIntent?token=12345/#Intent;scheme=https;package=net.openid.appauthdemo S.browser_fallback_url=http%3A%2F%2Fa-fallback-url;end">App</a>

Link is not opened:

<a href="intent://dummyIntent?token={{user.token}}/#Intent;scheme=https;package=net.openid.appauthdemo S.browser_fallback_url=http%3A%2F%2Fa-fallback-url;end">App</a>

Also tried extra param, same problem:

<a href="intent://dummyIntent/#Intent;scheme=https;package=net.openid.appauthdemo S.browser_fallback_url=http%3A%2F%2Fa-fallback-url;S.token={{user.token}};end">App</a>

Hint: Link is shown as "unsafe" if copied to clipboard

unsafe:intent://dummyIntent?token=/#Intent;scheme=https;package=net.openid.appauthdemo;end

Any suggestions to solve this?

Marc Stroebel
  • 2,295
  • 1
  • 12
  • 21

1 Answers1

0

Found a solution: Used a safeUrl-Pipe

import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
  name: 'safeUrl'
})
export class SafeUrlPipe implements PipeTransform {
  constructor(private domSanitizer: DomSanitizer) {}
  transform(url) {
    return this.domSanitizer.bypassSecurityTrustResourceUrl(url);
}
}

Template:

<a [attr.href]="intentLink | async | safeUrl">App</a>

How to avoid adding prefix “unsafe” to link by Angular-2?

Marc Stroebel
  • 2,295
  • 1
  • 12
  • 21