在我的Angular项目中,我刚刚实现了Amazon Cognito Hosted UI来处理我的登录,如下所示:

现在,当我的用户点击我的登录按钮时,他们会被重定向到另一个网址,如 https://[domain].amazoncognito.com/login?redirect_uri=http://localhost:4200/&response_type=code&client_id=[some id] ,以便登录并在成功的情况下重定向回我的Angular网址 .

在实现之前,我有一个简单的登录页面和一个authguard来保护我的路线 stored the attempted URL and redirected back after sign in . 因为我只是在Angular上,所以一切顺利 .

现在,由于Cognito Hosted UI的功能,当我的用户被重定向到托管UI时,尝试的URL参数会丢失 .

My question: 即使使用此重定向,有没有办法保留我尝试过的URL参数?

More informations

我没有登录组件,因为它由Cognito Hosted UI处理 .

这是调用我的Cognito Hosted UI的组件的摘录:

navbar.component.ts

@Component({
  selector: 'app-navbar',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.scss']
})
export class NavbarComponent implements OnDestroy, OnInit {

  [...]

  constructor(
    @Inject(LOCALE_ID) protected localeId: string,
    private router: Router,
    private authService: AuthService,
    private usersService: UsersService
  ) { }

  [...]

  signIn() {
    this.authService.signIn();
  }

}

navbar.component.html

<div class="navbar-item" *appShowIfSignedIn="false">
  <a class="button" (click)="signIn()">Sign in</a>
</div>

以下是我的AuthService的摘录:

auth.service.ts

@Injectable({ providedIn: 'root' })
export class AuthService {

  private url = 'https://' + '[domain].auth.eu-central-1.amazoncognito.com' + '/login?redirect_uri=' + 'http://localhost:4200/' + '&response_type=' + 'code' + '&client_id=' + '[some id]';

  constructor(
    private ngZone: NgZone,
    private authStore: AuthStore
  ) {
    Hub.listen('auth', this, 'AuthCodeListener');
  }

  onHubCapsule(capsule: any) {
    const { channel, payload } = capsule;
    if (channel === 'auth' && payload.event === 'signIn') {
      this.ngZone.run(() => {
        this.currentAuthenticatedUser().subscribe(
          (user: any) => {
            const isSignedIn = true;
            const accessToken = user.signInUserSession.accessToken.jwtToken;
            const sub = user.signInUserSession.accessToken.payload['sub'];
            this.authStore.update({
              signedIn: isSignedIn,
              accessToken: accessToken,
              sub: sub
            });
          }
        );
      });
    }
  }

  signIn() {
    window.location.assign(this.url);
  }

谢谢你的帮助