question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help with refreshing token (Keep getting token_not_provided error)

See original GitHub issue

I have an app that has a search screen that allows users to search for products. My token expires after 60 mins and has a TTL of 7 days so if users come back to the browser say after a day of not searching and start searching I want to refresh the token if it can be refreshed. The search() function retrieves a list of products which is completely separate from the refreshToken() function which only attempts to refresh the token. Currently the search() works completely fine until the token expires. When the token expires it goes to the refreshToken() but my API endpoint to refresh the token is never called. Instead the get request request in search() keeps returning a token_not_provided error which is weird because somehow it is getting deleted or not sent which leads me to believe the problem is my refreshToken() function

export function getAuthHttp(http, storage) {
  return new AuthHttp(new AuthConfig({
    headerName: 'Authorization',
    headerPrefix: 'Bearer',
    noJwtError: true,
    globalHeaders: [{'Accept': 'application/json', 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest'}],
    tokenGetter: (() =>   storage.ready().then(() => storage.get('token')))
  }), http);
}



search(): Observable<any> {
  this.auth.refreshToken();
    return this.authHttp.get('')
      .map(
        (response: Response) => {
          return response.json().info;
        },
        (error: Response) => {
            console.log(error);
        }
      );
}

onSearch(event)
  {
    let keyword = event.target.value;
    this.searchService.search(keyword)
      .subscribe(
        (loc: Home[]) => this.loc = loc,
        (error: Response) => {
          console.log(error);
          //alert("Session Expired. You must login again.");
        }
      )
}

refreshToken(): Observable<string> {
  console.log(" is token valid",this.isTokenValid());
  if ( this.isTokenValid()) {
    return this.authHttp.get('http://api.app/api/refresh?token=' + this.token).map((rsp) => {
      this.token = rsp.json().token;
      this.storage.ready().then(() => this.storage.set('token', this.token));
      return this.token;
    });
  } else {
    return Observable.of(this.token);
  }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
escardincommented, Jun 6, 2017

this.auth.refreshToken(); <- this returns an observable, but it doesn’t actually do anything until you subscribe()

search() should probably look like this:

search(): Observable<any> {
  return this.auth.refreshToken()
   .flatMap(()=>this.authHttp.get(''))
      .map(
        (response: Response) => {
          return response.json().info;
        },
        (error: Response) => {
            console.log(error);
        }
      );
}

0reactions
stale[bot]commented, Oct 26, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you have not received a response for our team (apologies for the delay) and this is still a blocker, please reply with additional information or just a ping. Thank you for your contribution! 🙇‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is a refresh_token not provided by OAuth2 servers ...
A refresh token SHOULD NOT be included. If the request failed client authentication or is invalid, the authorization server returns an error ......
Read more >
How do you refresh Token ? · Issue #186 · tymondesigns/jwt ...
Hi, I am having the same problem , I'm using laravel 4 and have a method that updates the token but is returned...
Read more >
Refresh Token - Constant Contact Community - 332029
That error message occurs when the Refresh Token you used was invalidated by generating ... My refresh_token keeps getting invalidated also for some...
Read more >
zcrmsdk/oauth/exception/ZohoOAuthException with message ...
The error is: 'zcrmsdk/oauth/exception/ZohoOAuthException with message 'Refresh token is not provided.'' There is no accompanying stack trace.
Read more >
Confusing error message on failed refresh token request
I got authorizing and requesting initial access and refresh tokens all working as expected. However when refreshing an access token using the /{ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found