benbaran / adal-angular4

Angular 4/5/6/7 ADAL Wrapper
MIT License
87 stars 106 forks source link

this.adalService.acquireToken method giving timeout error on first time login. #94

Open rahulraibit opened 5 years ago

rahulraibit commented 5 years ago

Hi I am facing one issue with the this.adalService.acquireToken method only during first time login. I am getting timeout error but after login if i will do page refresh then this.adalService.acquireToken method returning proper token.

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> | Observable<HttpSentEvent | HttpHeaderResponse | HttpProgressEvent | HttpResponse<any> | HttpUserEvent<any>> { if (req && req.params instanceof CustomAuthParams && req.params.AuthNotRequired) { return this.handleAuthentication(req, next, null); } else { if (!this.adalService.userInfo.authenticated) { console.log(req, 'Cannot send request to registered endpoint if the user is not authenticated.'); } return this.adalService.acquireToken(resourceURL).timeout(this.API_TIMEOUT).pipe( mergeMap((token: string) => { return this.handleAuthentication(req, next, token); }) ).catch(err => { console.log('acquire token error', err); return throwError(err) }) } }

One more thing I have noticed that this problem is only coming on some deployed environment not in localhost.

I found one more interesting part is that if I will open console window then only I will get "Token renewal operation failed due to timeout". If I will not open console window then everything is working as expected.

Don't know what is going on.

Any help will be appreciated. Thanks

leonixyz commented 5 years ago

Can you tell which version of adal-angular you have in your node_modules?

pamidivenkat commented 5 years ago

I'm also having same issue. I'm using 3.0.7

leonixyz commented 5 years ago

@pamidivenkat what you refer to is surely the version of adal-angular4, but I want to know the version of adal-angular (note there is no trailing 4).

adal-angular is a dependency of adal-angular4 and since there is an issue with newer versions, see issue #91 , i did a PR some time ago to fix it to 1.0.15

pamidivenkat commented 5 years ago

adal-angular4@^3.0.7: dependencies: adal-angular "=1.0.15"

adal-angular@=1.0.15: version "1.0.15"

freelancernht commented 5 years ago

Any solution for this error ?? This is happening couple of times

geerzo commented 5 years ago

I have only seen this when a newer version of adal-angular is installed. What are the steps to reproduce?

freelancernht commented 5 years ago

I have following config which was working with before but now throws timeout error to get token for webapi. Though the webApi call brings the data but I have a global error logger which logs the Timeout error and shows to user which is annoying. This is also happening for lazy loaded modules

export const environment = { production: false, adalConfig: { tenant: 'common', clientId: '[Client ID]', redirectUri: 'http://localhost:4200/', postLogoutRedirectUri: 'http://localhost:4200/logout', endpoints: { 'https://webapi.azurewebsites.net': 'https://roys.com/[Identifier]', 'https://graph.microsoft.com': 'https://graph.microsoft.com', 'https://api.powerbi.com': 'https://analysis.windows.net/powerbi/api', 'https://us.api.flow.microsoft.com': 'https://service.flow.microsoft.com/', 'https://management.azure.com': 'https://service.flow.microsoft.com/' }, isAngular: true }, apiUrl: 'https://webapi.azurewebsites.net/api/', flowApiURL: 'https://us.api.flow.microsoft.com/', azureApiUrl: 'https://management.azure.com/', botConfig: { directLineSecretkey: [secret], bingSpeechToTextSecretKey:[secret], azureBotServiceId: 'TestBot' } };

geerzo commented 5 years ago

I can't reproduce you problem. Can you give me two things: 1) the output of npm list --depth=1 2) some sort of stack trace of where the error is being generated. From what you say, everything work, you just get a random error.

freelancernht commented 5 years ago

Steps To Reproduce:

  1. Login
  2. There should be an api call Call another api which requires token.
  3. logout
  4. Again login.
  5. Error throws before getting the token for api call.

Error Log is attached Below

Output of npm list --depth=1

+-- @angular-devkit/build-angular@0.11.1 | +-- @angular-devkit/architect@0.11.1 | +-- @angular-devkit/build-optimizer@0.11.1 | +-- @angular-devkit/build-webpack@0.11.1 | +-- @angular-devkit/core@7.1.1 | +-- @ngtools/webpack@7.1.1 | +-- ajv@6.5.3 | +-- autoprefixer@9.3.1 | +-- circular-dependency-plugin@5.0.2 | +-- clean-css@4.2.1 | +-- copy-webpack-plugin@4.5.4 | +-- file-loader@2.0.0 | +-- glob@7.1.3 | +-- istanbul@0.4.5 | +-- istanbul-instrumenter-loader@3.0.1 | +-- karma-source-map-support@1.3.0 | +-- less@3.8.1 | +-- less-loader@4.1.0 | +-- license-webpack-plugin@2.0.2 | +-- loader-utils@1.1.0 | +-- mini-css-extract-plugin@0.4.4 | +-- minimatch@3.0.4 | +-- node-sass@4.10.0 | +-- opn@5.3.0 | +-- parse5@4.0.0 | +-- portfinder@1.0.17 | +-- postcss@7.0.5 | +-- postcss-import@12.0.0 | +-- postcss-loader@3.0.0 | +-- raw-loader@0.5.1 | +-- rxjs@6.3.3 | +-- sass-loader@7.1.0 | +-- semver@5.5.1 | +-- source-map-loader@0.2.4 | +-- source-map-support@0.5.9 | +-- speed-measure-webpack-plugin@1.2.3 | +-- stats-webpack-plugin@0.7.0 | +-- style-loader@0.23.1 | +-- stylus@0.54.5 | +-- stylus-loader@3.0.2 | +-- terser-webpack-plugin@1.1.0 | +-- tree-kill@1.2.0 | +-- webpack@4.23.1 | +-- webpack-dev-middleware@3.4.0 | +-- webpack-dev-server@3.1.10 | +-- webpack-merge@4.1.4 | +-- webpack-sources@1.3.0 | -- webpack-subresource-integrity@1.1.0-rc.6 +-- @angular/animations@6.1.10 |-- tslib@1.9.3 deduped +-- @angular/cdk@6.4.7 | -- tslib@1.9.3 deduped +-- @angular/cli@6.1.1 | +-- @angular-devkit/architect@0.7.1 | +-- @angular-devkit/core@0.7.1 | +-- @angular-devkit/schematics@0.7.1 | +-- @schematics/angular@0.7.1 | +-- @schematics/update@0.7.1 | +-- opn@5.3.0 deduped | +-- rxjs@6.3.3 | +-- semver@5.4.1 | +-- symbol-observable@1.2.0 |-- yargs-parser@10.1.0 +-- @angular/common@6.1.10 | -- tslib@1.9.3 deduped +-- @angular/compiler@6.1.10 |-- tslib@1.9.3 deduped +-- @angular/compiler-cli@6.1.10 | +-- chokidar@1.7.0 | +-- minimist@1.2.0 | +-- reflect-metadata@0.1.12 | -- tsickle@0.32.1 +-- @angular/core@6.1.10 |-- tslib@1.9.3 deduped +-- @angular/forms@6.1.10 | -- tslib@1.9.3 deduped +-- @angular/http@6.1.10 |-- tslib@1.9.3 deduped +-- @angular/language-service@6.1.10 +-- @angular/material@6.4.7 | +-- parse5@5.1.0 | -- tslib@1.9.3 deduped +-- @angular/platform-browser@6.1.10 |-- tslib@1.9.3 deduped +-- @angular/platform-browser-dynamic@6.1.10 | -- tslib@1.9.3 deduped +-- @angular/router@6.1.10 |-- tslib@1.9.3 deduped +-- @ng-bootstrap/ng-bootstrap@3.3.1 | -- tslib@1.9.3 deduped +-- @ngx-formly/core@4.8.2 |-- tslib@1.9.3 deduped +-- @ngx-formly/material@4.8.2 | -- tslib@1.9.3 deduped +-- @tinymce/tinymce-angular@2.0.0 |-- tslib@1.9.2 +-- @types/jasmine@2.5.54 +-- @types/jasminewd2@2.0.3 | -- @types/jasmine@2.5.54 deduped +-- @types/node@6.0.94 +-- adal-angular4@3.0.16 |-- adal-angular@1.0.15 +-- angular-font-awesome@3.1.2 +-- angular-tree-component@8.0.1 | +-- @types/lodash@4.14.119 | +-- lodash@4.17.11 | +-- mobx@3.6.2 | -- mobx-angular@2.1.1 +-- bootstrap@4.1.3 +-- classlist.js@1.1.20150312 +-- core-js@2.5.3 +-- d3@5.0.0 | +-- d3-array@1.2.1 | +-- d3-axis@1.0.8 | +-- d3-brush@1.0.4 | +-- d3-chord@1.0.4 | +-- d3-collection@1.0.4 | +-- d3-color@1.0.3 | +-- d3-contour@1.2.0 | +-- d3-dispatch@1.0.3 | +-- d3-drag@1.2.1 | +-- d3-dsv@1.0.8 | +-- d3-ease@1.0.3 | +-- d3-fetch@1.1.0 | +-- d3-force@1.1.0 | +-- d3-format@1.2.2 | +-- d3-geo@1.10.0 | +-- d3-hierarchy@1.1.5 | +-- d3-interpolate@1.1.6 | +-- d3-path@1.0.5 | +-- d3-polygon@1.0.3 | +-- d3-quadtree@1.0.3 | +-- d3-random@1.1.0 | +-- d3-scale@2.0.0 | +-- d3-scale-chromatic@1.2.0 | +-- d3-selection@1.3.0 | +-- d3-shape@1.2.0 | +-- d3-time@1.0.8 | +-- d3-time-format@2.1.1 | +-- d3-timer@1.0.7 | +-- d3-transition@1.1.1 | +-- d3-voronoi@1.1.2 |-- d3-zoom@1.7.1 +-- eslint@4.13.1 | +-- ajv@5.5.2 | +-- babel-code-frame@6.26.0 | +-- chalk@2.2.2 | +-- concat-stream@1.6.0 | +-- cross-spawn@5.1.0 | +-- debug@3.1.0 | +-- doctrine@2.0.2 | +-- eslint-scope@3.7.1 | +-- espree@3.5.2 | +-- esquery@1.0.0 | +-- estraverse@4.2.0 | +-- esutils@2.0.2 | +-- file-entry-cache@2.0.0 | +-- functional-red-black-tree@1.0.1 | +-- glob@7.1.2 | +-- globals@11.1.0 | +-- ignore@3.3.7 | +-- imurmurhash@0.1.4 | +-- inquirer@3.3.0 | +-- is-resolvable@1.0.1 | +-- js-yaml@3.10.0 | +-- json-stable-stringify-without-jsonify@1.0.1 | +-- levn@0.3.0 | +-- lodash@4.17.4 | +-- minimatch@3.0.4 deduped | +-- mkdirp@0.5.1 | +-- natural-compare@1.4.0 | +-- optionator@0.8.2 | +-- path-is-inside@1.0.2 | +-- pluralize@7.0.0 | +-- progress@2.0.0 | +-- require-uncached@1.0.3 | +-- semver@5.4.1 deduped | +-- strip-ansi@4.0.0 | +-- strip-json-comments@2.0.1 | +-- table@4.0.2 | -- text-table@0.2.0 +-- font-awesome@4.7.0 +-- hammerjs@2.0.8 +-- jasmine-core@2.6.4 +-- jasmine-spec-reporter@4.1.1 |-- colors@1.1.2 +-- UNMET PEER DEPENDENCY jquery@1.9.1 - 3 +-- karma@1.7.1 | +-- bluebird@3.5.1 | +-- body-parser@1.18.2 | +-- chokidar@1.7.0 deduped | +-- colors@1.1.2 deduped | +-- combine-lists@1.0.1 | +-- connect@3.6.5 | +-- core-js@2.5.3 deduped | +-- di@0.0.1 | +-- dom-serialize@2.2.1 | +-- expand-braces@0.1.2 | +-- glob@7.1.2 deduped | +-- graceful-fs@4.1.11 | +-- http-proxy@1.16.2 | +-- isbinaryfile@3.0.2 | +-- lodash@3.10.1 | +-- log4js@0.6.38 | +-- mime@1.6.0 | +-- minimatch@3.0.4 deduped | +-- optimist@0.6.1 | +-- qjobs@1.1.5 | +-- range-parser@1.2.0 | +-- rimraf@2.6.2 | +-- safe-buffer@5.1.1 | +-- socket.io@1.7.3 | +-- source-map@0.5.7 | +-- tmp@0.0.31 | -- useragent@2.2.1 +-- karma-chrome-launcher@2.1.1 | +-- fs-access@1.0.1 |-- which@1.3.0 +-- karma-cli@1.0.1 | -- resolve@1.5.0 +-- karma-coverage-istanbul-reporter@1.3.0 | +-- istanbul-api@1.2.1 |-- minimatch@3.0.4 deduped +-- karma-jasmine@1.1.1 +-- karma-jasmine-html-reporter@0.2.2 | -- karma-jasmine@1.1.1 deduped +-- microsoft-speech-browser-sdk@0.0.12 +-- ng-multiselect-dropdown@0.1.7 |-- tslib@1.9.3 deduped +-- ngx-device-detector@1.3.4 +-- UNMET PEER DEPENDENCY popper.js@^1.14.3 +-- powerbi-client@2.5.1 | +-- http-post-message@0.2.3 | +-- powerbi-models@1.0.4 | +-- powerbi-router@0.1.5 | -- window-post-message-proxy@0.2.5 +-- protractor@5.1.2 | +-- @types/node@6.0.94 deduped | +-- @types/q@0.0.32 | +-- @types/selenium-webdriver@2.53.43 | +-- blocking-proxy@0.0.5 | +-- chalk@1.1.3 | +-- glob@7.1.2 deduped | +-- jasmine@2.8.0 | +-- jasminewd2@2.2.0 | +-- optimist@0.6.1 deduped | +-- q@1.4.1 | +-- saucelabs@1.3.0 | +-- selenium-webdriver@3.0.1 | +-- source-map-support@0.4.18 | +-- webdriver-js-extender@1.0.0 |-- webdriver-manager@12.0.6 +-- rxjs@6.3.3 | -- tslib@1.9.3 deduped +-- rxjs-compat@6.3.3 +-- stacktrace-js@2.0.0 | +-- error-stack-parser@2.0.1 | +-- stack-generator@2.0.2 |-- stacktrace-gps@3.0.2 +-- ts-node@3.2.2 | +-- arrify@1.0.1 | +-- chalk@2.2.2 deduped | +-- diff@3.4.0 | +-- make-error@1.3.0 | +-- minimist@1.2.0 deduped | +-- mkdirp@0.5.1 deduped | +-- source-map-support@0.4.18 deduped | +-- tsconfig@6.0.0 | +-- v8flags@3.0.1 | -- yn@2.0.0 +-- tslib@1.9.3 +-- tslint@5.7.0 | +-- babel-code-frame@6.26.0 deduped | +-- colors@1.1.2 deduped | +-- commander@2.12.2 | +-- diff@3.4.0 deduped | +-- glob@7.1.2 deduped | +-- minimatch@3.0.4 deduped | +-- resolve@1.5.0 deduped | +-- semver@5.4.1 deduped | +-- tslib@1.9.3 deduped |-- tsutils@2.13.1 +-- typescript@2.7.2 +-- web-animations-js@2.3.1 `-- zone.js@0.8.26

localhost-1545146588758.txt

geerzo commented 5 years ago

Not sure...I can't seem to find a way to reproduce this. Have you compared what you do to the example application? What are the differences?