{"id":20611922,"url":"https://github.com/jimmyn/angular-aws-apig","last_synced_at":"2025-04-15T05:43:06.336Z","repository":{"id":57178022,"uuid":"56227020","full_name":"jimmyn/angular-aws-apig","owner":"jimmyn","description":"Angular interceptor for $http service that signs all requests to AWS APIGateway with IAM credentials.","archived":false,"fork":false,"pushed_at":"2016-05-16T14:40:35.000Z","size":928,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T05:43:01.188Z","etag":null,"topics":["angular-interceptor","aws","aws-apigateway","iam-credentials","interceptor"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimmyn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-14T10:03:12.000Z","updated_at":"2019-10-22T08:49:05.000Z","dependencies_parsed_at":"2022-09-10T23:55:02.381Z","dependency_job_id":null,"html_url":"https://github.com/jimmyn/angular-aws-apig","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmyn%2Fangular-aws-apig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmyn%2Fangular-aws-apig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmyn%2Fangular-aws-apig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmyn%2Fangular-aws-apig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimmyn","download_url":"https://codeload.github.com/jimmyn/angular-aws-apig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016307,"owners_count":21198828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular-interceptor","aws","aws-apigateway","iam-credentials","interceptor"],"created_at":"2024-11-16T10:22:36.911Z","updated_at":"2025-04-15T05:43:06.316Z","avatar_url":"https://github.com/jimmyn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# angular-aws-apig\n\nThis 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.\n\n## Installing it\n\nYou have several options:\n\n````bash\nbower install angular-aws-apig --save\n````\n\n````bash\nnpm install angular-aws-apig --save\n````\n\nOr just include `dist/angular-aws-apig.js` or `dist/angular-aws-apig.min.js` in to your index.html\n\n## Basic usage\n\n````js\nangular.module('app', ['angular-aws-apig'])\n.config(function Config($httpProvider, APIGInterceptorProvider) {\n\tAPIGInterceptorProvider.config({\n\t\theaders: {},\n\t\tregion: 'us-east-1',\n\t\tservice: 'execute-api',\n\t\turlRegex: ''\n\t})\n\n\t/* @ngInject */\n\tAPIGInterceptorProvider.headersGetter = function(myService, request) {\n\t\tmyService.doSomething();\n\t\treturn request.headers;\n\t};\n\n\t/* @ngInject */\n\tAPIGInterceptorProvider.credentialsGetter = function(store, request) {\n\t\treturn store.get('credentials');\n\t};\n\n\t$httpProvider.interceptors.push('APIGInterceptor');\n});\n````\n\n## APIGInterceptorProvider.config\n\n* `headers` - global headers that would be added to all api requests (default: `{}`)\n* `region` - AWS region (default: `us-east-1`)\n* `service` - AWS service (default: `execute-api`)\n* `urlRegex` - RegEx string, Interceptor would ignore requests to url that doesn't match this RegEx. (default: `''`)\n\nAll options could be passed in `APIGInterceptorProvider.config` function as a single object or assigned directly\n````js\nAPIGInterceptorProvider.urlRegex = 'myapi.com';\n````\n\n## APIGInterceptorProvider.headersGetter\nA 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.\n\n````js\nAPIGInterceptorProvider.headersGetter = function($rootScope, request) {\n\t\tvar headers = request.headers\n\t\theaders.foo = $rootScope.foo;\n\t\treturn headers;\n\t};\n````\n\n## APIGInterceptorProvider.credentialsGetter\nA 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.   \n**If this function is not specified `APIGInterceptor` will try to get credentials from `AWS.config.credentials`**\n\n````js\nAPIGInterceptorProvider.credentialsGetter = function(awsCredentials, auth) {\n\t\treturn awsCredentials.get(auth.idToken);\n\t};\n````\n\nIn this example `awsCredentials.get` returns a promise that resolves with `credentials` object\n````js\n  {\n    accessKeyId: 'accessKeyId',\n    secretAccessKey: 'secretAccessKey',\n    sessionToken: 'sessionToken'\n  }\n````\n\n## $APIGError event\nThis event would be triggered on request error.\n````js\n$rootScope.$on('$APIGError', (event, error) =\u003e {\n  $log.debug(event, error);\n});\n````\n\n## Credits\nThis library is a wrapper around [aws4](https://github.com/mhart/aws4) npm package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmyn%2Fangular-aws-apig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimmyn%2Fangular-aws-apig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmyn%2Fangular-aws-apig/lists"}