import { Component , OnInit } from '@angular/core' ; import { OktaAuth , Tokens } from '@okta/okta-auth-js' ; import * as OktaSignIn from '@okta/okta-signin-widget' ; import sampleConfig from '../app.config' ; const DEFAULT_ORIGINAL_URI = window . location . origin ; @ Component ( { selector : 'app-login' , templateUrl : './login.component.html' , styleUrls : [ './login.component.css' ] } ) export class LoginComponent implements OnInit { signIn : any ; constructor ( public oktaAuth ) { this . signIn = new OktaSignIn ( { /**
             * Note: when using the Sign-In Widget for an OIDC flow, it still
             * needs to be configured with the base URL for your Okta Org. Here
             * we derive it from the given issuer for convenience.
             */ baseUrl : sampleConfig . oidc . issuer . split ( '/oauth2' ) [ 0 ] , clientId : sampleConfig . oidc . clientId , redirectUri : sampleConfig . oidc . redirectUri , logo : 'assets/angular.svg' , i18n : { en : { 'primaryauth.title' : 'Sign in to Angular & Company' , } , } , authClient : oktaAuth , useInteractionCodeFlow : sampleConfig . widget . useInteractionCodeFlow === 'true' , } ) ; } ngOnInit ( ) { const originalUri = this . oktaAuth . getOriginalUri ( ) ; if ( ! originalUri || originalUri === DEFAULT_ORIGINAL_URI ) { this . oktaAuth . setOriginalUri ( '/' ) ; } this . signIn . showSignInToGetTokens ( { el : '#sign-in-widget' , scopes : sampleConfig . oidc . scopes } ) . then ( ( tokens ) => { this . signIn . remove ( ) ; this . oktaAuth . handleLoginRedirect ( tokens ) ; } ) . catch ( ( err ) => { throw err ; } ) ; } ngOnDestroy ( ) { this . signIn . remove ( ) ; } }