Unable to execute OAuth2 with Okta using angular-oauth2-oidc framework

Looking to create an authentication module for an Angular application using Okta as the identity provider and implementing the angular-oauth2-oidc flow. Following a guide here: . However, encountering errors when running the web app. How can I troubleshoot this issue?

auth.module.ts

@NgModule({
    declarations: [
        RegisterFormComponent,
        SignInFormComponent,
        SignInPage,
    ],
    imports: [
        CommonModule,
        RouterModule.forChild(AUTH_ROUTES),
        HttpClientModule,
        OAuthModule.forRoot(),
    ],
    providers: [
        AuthNgOauth2OidcService,
    ]
})
export class AuthModule {
}

auth-ng-oauth2-oidc.service.ts

export class AuthNgOauth2OidcService implements AuthService {

    authConfig: AuthConfig = {

        // Identity Provider URL
        issuer: environment.authIssuer,

        // Redirect URL after login
        redirectUri: environment.authRedirectUri,

        // Client ID registered with the auth-server
        clientId: environment.authClientId,

        // Define scope for client permissions
        // Request offline_access for refresh token
        scope: 'openid profile email offline_access',
    };

    public constructor(
        private authService: OAuthService,
    ) {
        this.authService.configure(this.authConfig);
        this.authService.tokenValidationHandler = new JwksValidationHandler();
        this.authService.loadDiscoveryDocumentAndTryLogin().then();
    } 
}

package.json

  "dependencies": {
    "@angular/animations": "~8.0.1",
    "@angular/cdk": "^8.2.3",
    "@angular/common": "~8.0.1",
    "@angular/compiler": "~8.0.1",
    "@angular/core": "~8.0.1",
    "@angular/forms": "~8.0.1",
    "@angular/http": "~8.0.0-beta.10",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.0.1",
    "@angular/platform-browser-dynamic": "~8.0.1",
    "@angular/router": "~8.0.1",
    "@fortawesome/angular-fontawesome": "^0.5.0",
    "@fortawesome/fontawesome-svg-core": "^1.2.25",
    "@fortawesome/free-solid-svg-icons": "^5.11.2",
    "@ngrx/effects": "^8.5.2",
    "@ngrx/store": "^8.4.0",
    "angular-auth-oidc-client": "^10.0.10",
    "angular-oauth2-oidc": "^8.0.4",
    "core-js": "^2.5.4",
    "mathjs": "^6.2.3",
    "nativescript-angular": "~8.0.1",
    "ng-oidc-client": "^1.0.7",
    "oidc-client": "^1.10.0",
    "reflect-metadata": "~0.1.12",
    "rxjs": "~6.5.0",
    "tns-core-modules": "~6.0.0",
    "zone.js": "~0.9.1"
  },

Error Message:

angular-oauth2-oidc.js:1346 error loading discovery document TypeError: this.interceptor.intercept is not a function
    at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http.js:1228)
    ...
core.js:5847 ERROR Error: Uncaught (in promise): TypeError: this.interceptor.intercept is not a function
TypeError: this.interceptor.intercept is not a function
    at HttpInterceptorHandler.push../node_modules/@angular/common/fesm5/http.js.HttpInterceptorHandler.handle (http.js:1228)
    ...

Answer №1

Consider implementing the following code snippet within your auth.module.ts file's providers section:

providers: [
    {
        provide: HTTP_INTERCEPTORS,
        useClass: AuthNgOauth2OidcService,
        multi: true
    },
    ]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilize cypress to analyze the loading time of a webpage

My current challenge involves using cypress to carry out website tests. I am looking for a reliable method to measure the duration it takes for certain cypress commands to load or execute. As an example: //var startTime = SomeStopwatchFunction(); cy.visit( ...

Ensure a field is required if the integer field is not empty in Angular Schema Form

I am currently working on setting up a form using Angular JSON Schema Form. My goal is to make one field (dropdown1) required only when another field (number1) has been filled in. I have managed to successfully get the following form + schema to function p ...

There seems to be an issue with my React application that was built using Webpack 5 and compiled with TypeScript. The @tailwind directive is not functioning properly in the browser, and

As I embark on creating a fresh react application using Webpack 5, Tailwind CSS, and Typescript, I find myself at a crossroads. Despite piecing together various tutorials, I am struggling to configure the postcss-loader for Tailwind. While traditional .css ...

How to retrieve a stored value using Ionic 3 native storage

Hey there, I recently attempted to implement code from the Native Storage plugin documentation found at this link: Native Storage import { NativeStorage } from '@ionic-native/native-storage'; constructor(private nativeStorage: NativeStorag ...

Tips for transferring data from an Angular @Input property to another variable and displaying it in a child component

I am dealing with the following parent HTML structure: <p>Parent</p> <app-child [mainData]="mainData"></app-child> In parent.ts, I have the following code: mainData = []; ngOnInit() { this.myService((res)=>{ this.mainData = ...

Encountering issues with the enhanced Angular 16 application

Recently, I encountered an issue while upgrading my Angular 10 application to use Angular 16. Following the Angular Update Guide, I smoothly transitioned through the versions until reaching Angular 16. However, when running the "ng version" command in Visu ...

What steps are required to configure angular-eslint for a protractor project?

I am in the process of transitioning to eslint using angular-eslint due to TSLint being deprecated. While going through the documentation, I noticed that there is no mention of protractor. My question is, can the default .eslintrc.json configuration be use ...

Remove the export statement after transpiling TypeScript to JavaScript

I am new to using TypeScript. I have a project with Knockout TS, and after compiling it (using the Intellij plugin to automatically compile ts to js), this is my sample.ts file: import * as ko from "knockout"; ko; class HelloViewModel { language: Kn ...

What is the best way to submit form data along with an image using Angular?

Recently, I built an application where users can submit form data along with an uploaded image. Since I am new to Angular, I am facing some challenges in merging the user-submitted data model and the image upload using the FormData method. Can anyone guide ...

Limiting the number of characters in a PrimeNG Quill editor

I am currently working on implementing a maximum length for the editor. Here is the code snippet I am using: this.editorTextChange$$ = this.quillEditor.onTextChange.asObservable() .subscribe((ev) => { const limit = this.maxLength; // last cha ...

Unable to reference the namespace 'ThemeDefinition' as a valid type within Vuetify

Looking to develop a unique theme for Vuetify v3.0.0-alpha.10 and I'm working with my vuetify.ts plugin file. import "@mdi/font/css/materialdesignicons.css"; import "vuetify/lib/styles/main.sass"; import { createVuetify, ThemeDefinition } from "v ...

Unlock the Power of Angular: Leveraging ViewEncapsulation.Native to Access HTML Elements

I am encountering an issue where I am receiving an error when trying to access an HTML element by ID. The problem arises when I attempt to access the classList upon a user clicking a button to apply a different style class to the element. The class list an ...

Checking for undefined based on certain conditions

When looking at the following code snippet type stringUndefined = "string" | undefined; type What<T> = T extends undefined ? "true" : "false"; const no : What<stringUndefined> = ""; The value of ' ...

The Angular program is receiving significant data from the backend, causing the numbers to be presented in a disorganized manner within an

My Angular 7 application includes a service that fetches data from a WebApi utilizing EntityFramework to retrieve information. The issue arises when numeric fields with more than 18 digits are incorrectly displayed (e.g., the number 23434343434345353453,3 ...

What is the best way to update placeholders in Angular 8+?

I have a collection of items: a = ['apple', 'mango', 'grape', 'papaya', 'banana', 'cucumber']. An input element is present with a placeholder stating select from fruits (the array elements should ...

What is the best approach to develop a React Component Library adorned with Tailwind CSS and enable the main project to easily customize its theme settings?

Currently, I am in the process of developing an internal component library that utilizes Tailwind for styling. However, a question has arisen regarding how the consuming project can incorporate its own unique styles to these components. Although I have th ...

Steps to disable the tab functionality in PrimeNG's editor

To disable tabbing in PrimeNG's rich text editor, which uses Quill, through JavaScript, you can utilize the following code: keyboard: { bindings: { tab: false, handleEnter: { key: 13, handler: function() { ...

What is the process for upgrading ag-Grid to newer versions?

In the past, I was using: "ag-grid": "^18.1.2", "ag-grid-angular": "^18.1.1" Version "^18.1.1" of "ag-grid-enterprise". However, as my license expired, I obtained new versions of the licenses. I then included: "@ag-grid-community/angular": "^22.1.1", ...

Formula for a distinct conclusion of written words

Can I restrict input to only letters and numbers, with words like xls, xlsx, json, xml always appearing at the end of the line? This is the pattern I am currently using: Validators.pattern(/^[a-zA-Z0-9]+$/) ...

What is the proper way to specify the type for a proxy that encapsulates a third-party class?

I have developed a unique approach to enhancing Firestore's Query class by implementing a Proxy wrapper. The role of my proxy is twofold: If a function is called on the proxy, which exists in the Query class, the proxy will direct that function call ...