Angular module for OAuth API authentication and wrapper for Angular's HTTP Client.
$ npm install --save @hub9/angular-oauth-client// ...import{AuthModule}from'@hub9/angular-oauth-client';constapiConfig={apiId: '<Api_Id>',apiSecret: '<Api_Secret>',apiUrl: 'api/',apiOauthUrl: 'oauth/',unauthorizedRoute: '/login/',};
@NgModule({// ...imports: [// ...AuthModule.forRoot(apiConfig),// ...],// ...})exportclassAppModule{}import{AuthService}from'@hub9/angular-oauth-client';
@Component({...})exportclassMyComponent{constructor(privateauth: AuthService){}login(username,password){this.auth.login(username,password).subscribe(response=>{console.log('Auth data:',response);});}logout(){this.auth.logout();}httpRequests(){// Do a GET request using authentication headersthis.auth.get('myresource/1/').subscribe(data=>console.log(data));// Do a POST request using authentication headers and sending datathis.auth.post('myresource/',{name: 'name'}).subscribe(data=>console.log(data));// Do a PUT request using authentication headers and sending datathis.auth.put('myresource/1/',{name: 'name'}).subscribe(data=>console.log(data));// Do a DELETE request using authentication headersthis.auth.delete('myresource/1/').subscribe(()=>console.log('deleted'));}}$ git clone https://github.com/hub9co/angular-oauth-client.git
$ cd angular-oauth-client
$ npm install
$ npm run build