Skip to content

Angular authentication module for OAuth APIs

Notifications You must be signed in to change notification settings

hub9/angular-oauth-client

Repository files navigation


Angular OAuth Client

Angular module for OAuth API authentication and wrapper for Angular's HTTP Client.

Install

$ npm install --save @hub9/angular-oauth-client

Configure

// ...
import { AuthModule } from '@hub9/angular-oauth-client';

const apiConfig = {
  apiId: '<Api_Id>',
  apiSecret: '<Api_Secret>',
  apiUrl: 'api/',
  apiOauthUrl: 'oauth/',
  unauthorizedRoute: '/login/',
};

@NgModule({
  // ...
  imports: [
    // ...
    AuthModule.forRoot(apiConfig),
    // ...
  ],
  // ...
})
export class AppModule {}

Usage

import { AuthService } from '@hub9/angular-oauth-client';

@Component({...})
export class MyComponent {
  constructor(private auth: 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 headers
    this.auth.get('myresource/1/').subscribe(data => console.log(data));

    // Do a POST request using authentication headers and sending data
    this.auth.post('myresource/', { name: 'name' }).subscribe(data => console.log(data));

    // Do a PUT request using authentication headers and sending data
    this.auth.put('myresource/1/', { name: 'name' }).subscribe(data => console.log(data));

    // Do a DELETE request using authentication headers
    this.auth.delete('myresource/1/').subscribe(() => console.log('deleted'));
  }
}

Contribute

$ git clone https://github.com/hub9co/angular-oauth-client.git
$ cd angular-oauth-client
$ npm install
$ npm run build

About

Angular authentication module for OAuth APIs

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published