Socket
Socket
Sign inDemoInstall

angular2-http-auth

Package Overview
Dependencies
8
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    angular2-http-auth

Angular HTTP Auth


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
53.2 kB
Created
Weekly downloads
 

Readme

Source

Angular HTTP Auth

npm Version Build Status

Angular authenticated HTTP requests (no JWT required).

Inspired by angular2-jwt

Install

npm install angular2-http-auth

Usage

auth-http.module.ts

This is the configuration file. You can pass it default fixed headers as well as dynamic headers (such as the authorization token).

Make sure to import this module prior doing any authenticated HTTP call.

app.module.ts is often a good place to import it.

import { AuthHttp, AuthConfig } from 'angular2-http-auth';

export function authHttpServiceFactory(
  http: Http,
  tokenIsHereService: OptionalServiceThatProvidesTheAuthorizationToken,
) {
  return new AuthHttp(new AuthConfig({
    headers: {
      'Content-Type': 'application/json',
      Authorization: () => tokenIsHereService.authorizationKey,
    },
  }), http);
}

@NgModule({
  providers: [
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [Http, OptionalServiceThatProvidesTheAuthorizationToken]
    }
  ]
})
export class AuthHttpModule { }

It is very similar to angular2-jwt's, even though some parameters might be different.

app.module.ts

import { HttpModule } from '@angular/http';
import { AuthHttpModule } from './auth-http.module';

@NgModule({
  imports: [
    ...
    HttpModule,
    AuthHttpModule,
    ...
  ],

my-user-panel.service.ts

import { AuthHttp } from 'angular2-http-auth';
...
fetchPrivateStuff(): Observable<Response> {
  return this.authHttp.post(`https://my-site.com/privateStuff`, {});
}

TODO

  • Default headers
  • Default search params
  • Default body
  • withCredentials (cookies)

License

MIT © Gerard Rovira Sánchez

Keywords

FAQs

Last updated on 11 Dec 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc