Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hub9/angular-oauth-client
Angular authentication module for OAuth APIs
https://github.com/hub9/angular-oauth-client
angular oauth-api oauth2
Last synced: 22 days ago
JSON representation
Angular authentication module for OAuth APIs
- Host: GitHub
- URL: https://github.com/hub9/angular-oauth-client
- Owner: hub9
- Created: 2018-01-16T21:17:54.000Z (almost 7 years ago)
- Default Branch: v2
- Last Pushed: 2018-02-12T18:09:13.000Z (almost 7 years ago)
- Last Synced: 2024-12-18T03:09:42.190Z (28 days ago)
- Topics: angular, oauth-api, oauth2
- Language: TypeScript
- Size: 329 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Angular OAuth ClientAngular module for OAuth API authentication and wrapper for Angular's HTTP Client.
## Install
```bash
$ npm install --save @hub9/angular-oauth-client
```## Configure
```typescript
// ...
import { AuthModule } from '@hub9/angular-oauth-client';const apiConfig = {
apiId: '',
apiSecret: '',
apiUrl: 'api/',
apiOauthUrl: 'oauth/',
unauthorizedRoute: '/login/',
};@NgModule({
// ...
imports: [
// ...
AuthModule.forRoot(apiConfig),
// ...
],
// ...
})
export class AppModule {}
```## Usage
```typescript
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
```bash
$ git clone https://github.com/hub9co/angular-oauth-client.git
$ cd angular-oauth-client
$ npm install
$ npm run build
```