Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
http-auth-interceptor
✓ angular.module('myApp', ['http-auth-interceptor'])
✗ import { httpAuthInterceptor } from 'angular-http-auth'
This is the name of the AngularJS module to be included in your application's dependencies, not a direct JavaScript import.
authService
✓ function MyController($scope, authService) { /* ... */ }
✗ import { authService } from 'angular-http-auth'
The `authService` is provided via AngularJS's dependency injection system, not as a direct ES Module or CommonJS export for consumer-side import. It should be injected into controllers, services, or directives.
angular-http-auth
✓ require('angular-http-auth');
✗ import 'angular-http-auth';
For CommonJS environments (supported since v1.5.0), the package can be loaded via `require`. This makes the Angular module available but doesn't export any symbols directly to the requiring file. Direct ESM imports are not supported.
This quickstart demonstrates setting up a basic Express backend that requires authentication and an AngularJS application that utilizes `angular-http-auth` to intercept 401 responses, trigger a simulated login process, and re-attempt the failed request.
const express = require('express');
const app = express();
const port = 3000;
app.get('/api/protected-data', (req, res) => {
const token = req.headers.authorization;
if (!token || token !== 'Bearer my-valid-token') {
return res.status(401).send('Unauthorized');
}
res.json({ message: 'This is protected data!' });
});
app.listen(port, () => console.log(`Backend listening on port ${port}`));
// --- In your AngularJS app (e.g., app.js) ---
// Make sure to include angular.js before angular-http-auth.js
// E.g., <script src="node_modules/angular/angular.js"></script>
// <script src="node_modules/angular-http-auth/dist/angular-http-auth.js"></script>
angular.module('myApp', ['http-auth-interceptor'])
.config(function($httpProvider) {
// $httpProvider.interceptors.push('authInterceptor'); // Not needed, http-auth-interceptor registers itself
})
.run(function($rootScope, $log, authService, $http) {
$rootScope.username = '';
$rootScope.password = '';
$rootScope.isAuthenticated = false;
$rootScope.$on('event:auth-loginRequired', function() {
$log.warn('Authentication required! Showing login dialog...');
// In a real app, you'd show a modal or redirect to a login page
$rootScope.showLoginDialog = true;
});
$rootScope.$on('event:auth-loginConfirmed', function(event, data) {
$log.info('Login confirmed!', data);
$rootScope.isAuthenticated = true;
$rootScope.showLoginDialog = false;
});
$rootScope.$on('event:auth-loginCancelled', function(event, data) {
$log.info('Login cancelled!', data);
$rootScope.isAuthenticated = false;
$rootScope.showLoginDialog = false;
});
$rootScope.login = function() {
// Simulate login request
$log.info(`Attempting login for ${$rootScope.username}`);
if ($rootScope.username === 'user' && $rootScope.password === 'pass') {
// Assuming a successful login would return a token or confirm success
// In a real app, this would be an actual $http call to your auth endpoint
$log.info('Simulated login successful. Confirming authService...');
authService.loginConfirmed({ token: 'my-valid-token', user: $rootScope.username });
} else {
$log.error('Invalid credentials.');
authService.loginCancelled(); // Clear buffered requests
}
};
$rootScope.logout = function() {
$log.info('Logging out...');
authService.loginCancelled();
$rootScope.username = '';
$rootScope.password = '';
};
// Example protected API call
$rootScope.fetchProtectedData = function() {
$http.get('/api/protected-data', {
headers: { 'Authorization': `Bearer ${$rootScope.isAuthenticated ? 'my-valid-token' : ''}` }
})
.then(function(response) {
$log.info('Protected data:', response.data);
})
.catch(function(error) {
if (error.status === 401) {
$log.error('Failed to fetch protected data: Unauthorized. Interceptor should handle this.');
} else {
$log.error('Error fetching protected data:', error);
}
});
};
// Call it initially to demonstrate behavior
$rootScope.fetchProtectedData();
});
Errors
Common errors & fixes
Error: [$injector:modulerr] Failed to instantiate module http-auth-interceptor due to: Error: [$injector:nomod] Module 'http-auth-interceptor' is not available!
The `http-auth-interceptor` module script was not loaded or `angular.module()` was called before the module was defined.
fixEnsure the `angular-http-auth.js` (or `.min.js`) script is included in your HTML *after* `angular.js` and *before* your main application script. Verify the module name is correctly spelled in `angular.module('myApp', ['http-auth-interceptor'])`. ReferenceError: authService is not defined
The `authService` was attempted to be used without being properly injected into an Angular component (controller, service, etc.).
fixEnsure `authService` is listed as a dependency in the function signature where it's being used, e.g., `app.controller('MyCtrl', function($scope, authService) { ... })`. HTTP 401 responses are not triggering login dialogs / are not being intercepted.
The module might not be correctly integrated into the AngularJS application, or a request has `ignoreAuthModule: true` set.
fixVerify that `http-auth-interceptor` is included in your main Angular module's dependencies: `angular.module('myApp', ['http-auth-interceptor'])`. Also, check the `$http` config for the specific request to ensure `ignoreAuthModule: true` is not inadvertently present. Audit
Dependencies
angularrequiredThis module is a direct extension of AngularJS 1.x's `$http` service and requires Angular to function.