{"id":18797134,"url":"https://github.com/leonardobazico/angular2-jwt-refresh","last_synced_at":"2025-10-19T13:10:45.188Z","repository":{"id":57179628,"uuid":"80867670","full_name":"leonardobazico/angular2-jwt-refresh","owner":"leonardobazico","description":"Refresh token support for angular2-jwt","archived":false,"fork":false,"pushed_at":"2018-03-06T13:00:02.000Z","size":26,"stargazers_count":40,"open_issues_count":11,"forks_count":15,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-27T07:48:01.528Z","etag":null,"topics":["angular","angular2","jwt","refresh-tokens"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leonardobazico.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-03T20:44:14.000Z","updated_at":"2023-08-21T07:54:44.000Z","dependencies_parsed_at":"2022-09-14T02:10:28.283Z","dependency_job_id":null,"html_url":"https://github.com/leonardobazico/angular2-jwt-refresh","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonardobazico%2Fangular2-jwt-refresh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonardobazico%2Fangular2-jwt-refresh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonardobazico%2Fangular2-jwt-refresh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leonardobazico%2Fangular2-jwt-refresh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leonardobazico","download_url":"https://codeload.github.com/leonardobazico/angular2-jwt-refresh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248743851,"owners_count":21154753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular2","jwt","refresh-tokens"],"created_at":"2024-11-07T22:07:14.415Z","updated_at":"2025-10-19T13:10:40.152Z","avatar_url":"https://github.com/leonardobazico.png","language":"TypeScript","readme":"# angular2-jwt-refresh ![Travis CI Status](https://travis-ci.org/leonardobazico/angular2-jwt-refresh.svg?branch=master)\n\nThis package extends [angular2-jwt](https://github.com/auth0/angular2-jwt) and was made to deal with refresh token.\n\n\n## Instalation\n\n```\nnpm i angular2-jwt-refresh --save\n```\n\nDon't forget to install the peer dependencies\n```\nnpm i @angular/core @angular/http angular2-jwt rxjs --save\n```\n\n\n## Configuration\n\n```typescript\nimport { NgModule } from '@angular/core';\nimport { Http, RequestOptions, Response } from '@angular/http';\nimport { AuthConfig } from 'angular2-jwt';\nimport { JwtConfigService, JwtHttp } from 'angular2-jwt-refresh';\n\n@NgModule({\n  providers: [{\n    provide: JwtHttp,\n    useFactory: getJwtHttp,\n    deps: [ Http, RequestOptions ]\n  }]\n})\nexport class AppModule {}\n\nexport function getJwtHttp(http: Http, options: RequestOptions) {\n  let jwtOptions = {\n    endPoint: 'https://myapi.domain.com/auth',\n    // optional\n    payload: { type: 'refresh' },\n    beforeSeconds: 600, // refresh tokeSn before 10 min\n    tokenName: 'refresh_token',\n    refreshTokenGetter: (() =\u003e localStorage.getItem('refresh_token')),\n    tokenSetter: ((res: Response): boolean | Promise\u003cvoid\u003e =\u003e {\n      res = res.json();\n\n      if (!res['id_token'] || !res['refresh_token']) {\n        localStorage.removeItem('id_token');\n        localStorage.removeItem('refresh_token');\n\n        return false;\n      }\n\n      localStorage.setItem('id_token', res['id_token']);\n      localStorage.setItem('refresh_token', res['refresh_token']);\n\n      return true;\n    })\n  };\n  let authConfig = new AuthConfig({\n    noJwtError: true,\n    globalHeaders: [{'Accept': 'application/json'}],\n    tokenGetter: (() =\u003e localStorage.getItem('id_token')),\n  });\n\n  return new JwtHttp(\n    new JwtConfigService(jwtOptions, authConfig),\n    http,\n    options\n  );\n}\n```\n\n## Using JwtHttp\n```typescript\nimport { Injectable } from '@angular/core';\nimport { Response } from '@angular/http';\nimport { JwtHttp } from 'angular2-jwt-refresh';\nimport { Observable } from 'rxjs/Observable';\nimport 'rxjs/Rx';\n\nimport { AppConfig } from '../AppConfig';\n\n@Injectable()\nexport class DataService {\n  private baseUrl: string = AppConfig.baseUrl + '/data';\n\n  constructor(private jwtHttp: JwtHttp) { }\n\n  getData(id: number): Observable\u003cany\u003e {\n    const url = this.baseUrl + '/' + id;\n\n    return this.jwtHttp\n      .get(url)\n      .map((res: Response) =\u003e {\n        return res.json();\n      });\n  }\n\n  saveData(data: any): Observable\u003cstring\u003e {\n    const url = this.baseUrl + '/' (data['id'] ? data['id'] : '');\n\n    return this.jwtHttp\n      .post(url, data)\n      .map((res: Response) =\u003e {\n        return res.json();\n      });\n  }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonardobazico%2Fangular2-jwt-refresh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleonardobazico%2Fangular2-jwt-refresh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleonardobazico%2Fangular2-jwt-refresh/lists"}