Angular-oauth2-oidc: Cannot read property 'responseType' of null

Created on 21 Jan 2019  路  5Comments  路  Source: manfredsteyer/angular-oauth2-oidc

Hello,

I have this error when I call the initImplicitFlow() method.

Error in initImplicitFlow TypeError: Cannot read property 'responseType' of null
    at angular-oauth2-oidc.js:943
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
    at Object.onInvoke (core.js:17289)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:390)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150)
    at zone.js:889
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:17280)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)

It's a new project for test this oidc library.
Here my package.json

{
  "name": "oauth2",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/http": "^7.2.1",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "angular-oauth2-oidc": "^5.0.2",
    "bootstrap": "^4.2.1",
    "core-js": "^2.5.4",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.12.0",
    "@angular/cli": "~7.2.2",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

And my AppComponent

```export class AppComponent {
title = 'oauth2';

constructor(private oAuthService: OAuthService) {
this.oAuthService.oidc = true;
this.oAuthService.issuer = 'http://localhost:20150/auth/realms/demo-oidc';
this.oAuthService.redirectUri = window.location.origin + '/index.html';
this.oAuthService.clientId = 'spa-client';
this.oAuthService.scope = 'openid profile email';

this.oAuthService.tokenValidationHandler = new JwksValidationHandler();
this.oAuthService.loadDiscoveryDocumentAndTryLogin()
  .then(d => {
    console.log('discovery and login OK', d);
  })
  .catch(err => console.log('discovery and login ERROR', err));

}
public login(): void {
this.oAuthService.initImplicitFlow();
}

public logout(): void {
this.oAuthService.logOut();
}
}
```

Thanks for your help :)

Most helpful comment

Hi,

After some tests, your sample work ;p with the last version (5.0.2).
And in my project, I have found that set configs like this.oAuthService.issuer = 'xxxxx' not work.
The 'config' const file work well with Angular DI or
this.oAuthService.configure(config);
or like this :

const config = new AuthConfig();
config.issuer = 'http://localhost:20150/auth/realms/demo-spring-oauth2';
config.clientId = 'webclient-app';
config.redirectUri = window.location.origin + '/index.html';
config.scope = 'openid profile email';

this.oAuthService.configure(config);

Here in oauth-service.ts, when I try to configure the library with
``javascript this.oAuthService.issuer = 'http://localhost:20150/auth/realms/demo-spring-oauth2'; this.oAuthService.clientId = 'webclient-app'; this.oAuthService.redirectUri = window.location.origin + '/index.html'; this.oAuthService.scope = 'openid profile email'; ```` this.config` is null

So I think that I must use this.oAuthService.configure(config) with new AuthConfig() object.

Sorry for the late answer :/ (UTC-10)
Thanks for your help :D

All 5 comments

Hmm, that does sound off. It would help if you could dig a little deeper, here's some tips on how:

  • Add some client side logging to see what's going on precisely
  • Try refactor to providing the configuration via Angular's DI system (see this and this for examples)
  • Try out my example, you should be able to just reconfigure it against your own demo IDS and run it
  • Dive into the source and/or debug your issue (looking at the place of your error I'd guess there's something amiss with the login details)

Good luck!

Hi,

After some tests, your sample work ;p with the last version (5.0.2).
And in my project, I have found that set configs like this.oAuthService.issuer = 'xxxxx' not work.
The 'config' const file work well with Angular DI or
this.oAuthService.configure(config);
or like this :

const config = new AuthConfig();
config.issuer = 'http://localhost:20150/auth/realms/demo-spring-oauth2';
config.clientId = 'webclient-app';
config.redirectUri = window.location.origin + '/index.html';
config.scope = 'openid profile email';

this.oAuthService.configure(config);

Here in oauth-service.ts, when I try to configure the library with
``javascript this.oAuthService.issuer = 'http://localhost:20150/auth/realms/demo-spring-oauth2'; this.oAuthService.clientId = 'webclient-app'; this.oAuthService.redirectUri = window.location.origin + '/index.html'; this.oAuthService.scope = 'openid profile email'; ```` this.config` is null

So I think that I must use this.oAuthService.configure(config) with new AuthConfig() object.

Sorry for the late answer :/ (UTC-10)
Thanks for your help :D

Good to hear you've found a solution. I've created #500 to try and prevent folks running into that trap in the future.

Yeah :D !!
I think oAuthService.issuer and other properties are just a get ?
In the #500, maybe you can keep the .configure(...) method if we use multi providers for example ? Just a suggest, I don't have try that.

Looking back, I think we can close _this_ issue as OP posted their solution, and some other issues and PRs handle the rest. Let us know if it should be reopened!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

godhar picture godhar  路  3Comments

jeroenheijmans picture jeroenheijmans  路  3Comments

CharlyRipp picture CharlyRipp  路  3Comments

andrea-spotsoftware picture andrea-spotsoftware  路  3Comments

PandaaAgency picture PandaaAgency  路  3Comments