okta and angular 8 authentication

678 views Asked by At

I have implemented okta authentication for angular 7 app. The flow is as follows:

  1. User lands on landing page clicks login button
  2. User is redirected to okta login
  3. In okta we have a flag which checks if user is new or not called "newUser"
  4. After login okta has to check the flag value and if true route to dashboard page if false then to form page.

How can okta handle this redirection?

1

There are 1 answers

0
Matt Raible On

You could create your own callback component and map your callback route to it instead of Okta's. The default callback component is here. The code in it is:

import { Component, OnInit } from '@angular/core';

import { OktaAuthService } from '../services/okta.service';

@Component({
  template: `<div>{{error}}</div>`
})
export class OktaCallbackComponent implements OnInit {
  error: string;

  constructor(private okta: OktaAuthService) {}

  async ngOnInit() {
    /**
     * Handles the response from Okta and parses tokens.
     */
    return this.okta.handleAuthentication()
      .then(() => {
        /**
         * Navigate back to the saved uri, or root of application.
         */
        const fromUri = this.okta.getFromUri();
        // add custom logic here
        window.location.replace(fromUri);
      })
      .catch(e => {
        this.error = e.toString();
      });
  }
}