npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-auth-bearer-token

v1.3.0

Published

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

Downloads

32

Readme

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