New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angular-auth-bearer-token

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-auth-bearer-token

[![Build Status](https://travis-ci.org/matmar10/angular-auth-bearer-token.svg?branch=master)](https://travis-ci.org/matmar10/angular-auth-bearer-token)

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Angular Auth Bearer Token Strategy

Build Status

AKA RFC 6750: https://tools.ietf.org/html/rfc6750

A simple an unobtrusive way to add bearer token authentication strategy to your angular project.

Installation

Install via Bower:

bower install angular-auth-bearer-token --save

Require the module in your app:

angular.module('yourApp', ['auth.bearer-token']);

How it works

An HTTP interceptor will automatically store the authorization header from any request with an Authorization header.

Future requests will always include the authorization token.

Event system

The following events are emitted via $emit on $rootScope:

  • auth:session-start - triggered when a token gets stored but no previous token existed
  • auth:session-end - triggered when the token is cleared
  • auth:session-update - triggered when a new token is stored

For auth:session-start and auth:session-update, the HTTP configuration is passed to the handler:

$rootScope.$on('auth:session-start', function (ev, response) {
  // logs the HTTP body returned that triggered the session start event
  $log.debug('The data from session start is:', response.body);
});

Configuration Options

  • header [default: Authorization] - What header should be checked/set for requests
  • log [default: debug] - Log level for logging; set to false to disable
  • tokenRegex [default: /Bearer/] - Regular expression to check if returned authorization header is suitable

Example

Disable logging
angular.module('myApp').config(function ('authBearerTokenHttpInterceptorProvider') {
  authBearerTokenHttpInterceptorProvider.configure({
    log: false
  });
});
Customize header and regex
angular.module('myApp').config(function ('authBearerTokenHttpInterceptorProvider') {
  authBearerTokenHttpInterceptorProvider.configure({
    // look/set `Auth` header
    header: 'Auth',
    // match anything
    tokenRegex: /[\s\S]*
  });
});

TODO

  • Check the RFC to see if we're missing anything here
  • What do you need? Let me know!

Testing

Clone it:

git clone https://github.com/matmar10/angular-auth-bearer-token.git

Install deps:

npm install && bower install

Test it:

grunt test

Contributing

Please adhere to JSHint code quality standard as specified in .jshintrc

Releases

  • 1.3.0: Move to $localStorage instead of $cookies to work around android issues on cordova
  • 1.2.0: Add configuration options for non-standard token names / header names
  • 1.1.0: Add configuration options and examples in README
  • 1.0.2: Add build status to README
  • 1.0.1: Add travis CI
  • 1.0.0: Upgrade to Angular 1.4 and use new $cookies API
  • 0.2.1: Downgrade all log levels to debug to allow supression in client apps
  • 0.2.0: Add event system
  • 0.1.1: Add JSHint as default task
  • 0.1.0: Initial release

Keywords

FAQs

Package last updated on 10 Feb 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc