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-aws-apig

v1.2.3

Published

Angular interceptor for $http service that signs all requests to AWS APIGateway with IAM credentials.

Downloads

59

Readme

angular-aws-apig

This library provides an Interceptor for angular $http service that signs all request to AWS APIGateway with IAM credentials. It is handy when you use temprorary IAM Credentials from AWS Cognito or Auth0. Although AWS APIGateway provides autogenerated Javascript SDK, you can't use it with angular $http service and you need to regenerate it every time you change something in the API.

Installing it

You have several options:

bower install angular-aws-apig --save
npm install angular-aws-apig --save

Or just include dist/angular-aws-apig.js or dist/angular-aws-apig.min.js in to your index.html

Basic usage

angular.module('app', ['angular-aws-apig'])
.config(function Config($httpProvider, APIGInterceptorProvider) {
	APIGInterceptorProvider.config({
		headers: {},
		region: 'us-east-1',
		service: 'execute-api',
		urlRegex: ''
	})

	/* @ngInject */
	APIGInterceptorProvider.headersGetter = function(myService, request) {
		myService.doSomething();
		return request.headers;
	};

	/* @ngInject */
	APIGInterceptorProvider.credentialsGetter = function(store, request) {
		return store.get('credentials');
	};

	$httpProvider.interceptors.push('APIGInterceptor');
});

APIGInterceptorProvider.config

  • headers - global headers that would be added to all api requests (default: {})
  • region - AWS region (default: us-east-1)
  • service - AWS service (default: execute-api)
  • urlRegex - RegEx string, Interceptor would ignore requests to url that doesn't match this RegEx. (default: '')

All options could be passed in APIGInterceptorProvider.config function as a single object or assigned directly

APIGInterceptorProvider.urlRegex = 'myapi.com';

APIGInterceptorProvider.headersGetter

A function that provides dynamic headers. It accepts $http request object as a parameter and must return headers object. You can pass angular dependencies in this function.

APIGInterceptorProvider.headersGetter = function($rootScope, request) {
		var headers = request.headers
		headers.foo = $rootScope.foo;
		return headers;
	};

APIGInterceptorProvider.credentialsGetter

A function that provides dynamic AWS IAM Credentials. It accepts $http request object as a parameter and must return credentials object. You can pass angular dependencies in this function. Function can return $q promise.
If this function is not specified APIGInterceptor will try to get credentials from AWS.config.credentials

APIGInterceptorProvider.credentialsGetter = function(awsCredentials, auth) {
		return awsCredentials.get(auth.idToken);
	};

In this example awsCredentials.get returns a promise that resolves with credentials object

  {
    accessKeyId: 'accessKeyId',
    secretAccessKey: 'secretAccessKey',
    sessionToken: 'sessionToken'
  }

$APIGError event

This event would be triggered on request error.

$rootScope.$on('$APIGError', (event, error) => {
  $log.debug(event, error);
});

Credits

This library is a wrapper around aws4 npm package.