Repository: auth0/angular-token-auth
Branch: master
Commit: e5730487b272
Files: 8
Total size: 8.4 KB
Directory structure:
gitextract_zsxopvnq/
├── .gitignore
├── .jshintrc
├── LICENSE.txt
├── README.md
├── auth.client.js
├── auth.server.js
├── index.html
└── package.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
.DS_Store
node_modules
================================================
FILE: .jshintrc
================================================
{
"node": true,
"esnext": true,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"strict": false,
"smarttabs": true,
"expr": true,
"evil": true,
"browser": true,
"regexdash": true,
"wsh": true,
"trailing": true,
"sub": true,
"unused": true,
"laxcomma": true,
"globals": {
"after": false,
"before": false,
"afterEach": false,
"beforeEach": false,
"describe": false,
"it": false,
"angular": false,
"Auth0Widget": false,
"Auth0": false
}
}
================================================
FILE: LICENSE.txt
================================================
The MIT License (MIT)
Copyright (c) 2015 Auth0, Inc. <support@auth0.com> (http://auth0.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
## angular-token-auth
Example of Token-based authentication in [AngularJS](http://angularjs.org) with [Express](http://expressjs.com).
### Build and Run
First, install dependencies using npm:
```sh
npm install
```
Run the example:
```sh
node auth.server.js
```
and go to [localhost:8080](http://localhost:8080).
### More advanced scenarios?
For a complete example handling social providers, enterprise authentication with LDAP/Active Directory, and user/password, check out [Auth0 Angular integration](https://github.com/auth0/auth0-angular).
## Issue Reporting
If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
## Author
[Auth0](auth0.com)
## License
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
================================================
FILE: auth.client.js
================================================
var myApp = angular.module('myApp', []);
//this is used to parse the profile
function url_base64_decode(str) {
var output = str.replace('-', '+').replace('_', '/');
switch (output.length % 4) {
case 0:
break;
case 2:
output += '==';
break;
case 3:
output += '=';
break;
default:
throw 'Illegal base64url string!';
}
return window.atob(output); //polifyll https://github.com/davidchambers/Base64.js
}
myApp.controller('UserCtrl', function ($scope, $http, $window) {
$scope.user = {username: 'john.doe', password: 'foobar'};
$scope.isAuthenticated = false;
$scope.welcome = '';
$scope.message = '';
$scope.submit = function () {
$http
.post('/authenticate', $scope.user)
.success(function (data, status, headers, config) {
$window.sessionStorage.token = data.token;
$scope.isAuthenticated = true;
var encodedProfile = data.token.split('.')[1];
var profile = JSON.parse(url_base64_decode(encodedProfile));
$scope.welcome = 'Welcome ' + profile.first_name + ' ' + profile.last_name;
})
.error(function (data, status, headers, config) {
// Erase the token if the user fails to log in
delete $window.sessionStorage.token;
$scope.isAuthenticated = false;
// Handle login errors here
$scope.error = 'Error: Invalid user or password';
$scope.welcome = '';
});
};
$scope.logout = function () {
$scope.welcome = '';
$scope.message = '';
$scope.isAuthenticated = false;
delete $window.sessionStorage.token;
};
$scope.callRestricted = function () {
$http({url: '/api/restricted', method: 'GET'})
.success(function (data, status, headers, config) {
$scope.message = $scope.message + ' ' + data.name; // Should log 'foo'
})
.error(function (data, status, headers, config) {
alert(data);
});
};
});
myApp.factory('authInterceptor', function ($rootScope, $q, $window) {
return {
request: function (config) {
config.headers = config.headers || {};
if ($window.sessionStorage.token) {
config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
}
return config;
},
responseError: function (rejection) {
if (rejection.status === 401) {
// handle the case where the user is not authenticated
}
return $q.reject(rejection);
}
};
});
myApp.config(function ($httpProvider) {
$httpProvider.interceptors.push('authInterceptor');
});
================================================
FILE: auth.server.js
================================================
var express = require('express');
var bodyParser = require('body-parser');
var jwt = require('jsonwebtoken'); //https://npmjs.org/package/node-jsonwebtoken
var expressJwt = require('express-jwt'); //https://npmjs.org/package/express-jwt
var secret = 'this is the secret secret secret 12356';
var app = express();
// We are going to protect /api routes with JWT
app.use('/api', expressJwt({secret: secret}));
app.use(bodyParser.json());
app.use('/', express.static(__dirname + '/'));
app.use(function(err, req, res, next){
if (err.constructor.name === 'UnauthorizedError') {
res.status(401).send('Unauthorized');
}
});
app.post('/authenticate', function (req, res) {
//TODO validate req.body.username and req.body.password
//if is invalid, return 401
if (!(req.body.username === 'john.doe' && req.body.password === 'foobar')) {
res.status(401).send('Wrong user or password');
return;
}
var profile = {
first_name: 'John',
last_name: 'Doe',
email: 'john@doe.com',
id: 123
};
// We are sending the profile inside the token
var token = jwt.sign(profile, secret, { expiresInMinutes: 60*5 });
res.json({ token: token });
});
app.get('/api/restricted', function (req, res) {
console.log('user ' + req.user.email + ' is calling /api/restricted');
res.json({
name: 'foo'
});
});
app.listen(8080, function () {
console.log('listening on http://localhost:8080');
});
================================================
FILE: index.html
================================================
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Angular Authentication</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script>
<script src="./auth.client.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="UserCtrl">
<span ng-show="isAuthenticated">{{welcome}}</span>
<form ng-show="!isAuthenticated" ng-submit="submit()">
<input ng-model="user.username" type="text" name="user" placeholder="Username" />
<input ng-model="user.password" type="password" name="pass" placeholder="Password" />
<input type="submit" value="Login" />
</form>
<div>{{error}}</div>
<div ng-show="isAuthenticated">
<a ng-click="callRestricted()" href="">Shh, this is private!</a>
<br>
<div>{{message}}</div>
<a ng-click="logout()" href="">Logout</a>
</div>
</div>
</body>
</html>
================================================
FILE: package.json
================================================
{
"name": "angular-token-auth",
"version": "0.1.0",
"dependencies": {
"body-parser": "^1.9.0",
"express": "~4.9.0",
"express-jwt": "~0.2.1",
"jsonwebtoken": "~0.4.0"
},
"description": "Example of Token-based authentication in [AngularJS](http://angularjs.org) with [Express](http://expressjs.com).",
"main": "auth.server.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/auth0/angular-token-auth.git"
},
"keywords": [
"angular",
"auth",
"jwt",
"express"
],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/auth0/angular-token-auth/issues"
},
"homepage": "https://github.com/auth0/angular-token-auth"
}
gitextract_zsxopvnq/ ├── .gitignore ├── .jshintrc ├── LICENSE.txt ├── README.md ├── auth.client.js ├── auth.server.js ├── index.html └── package.json
SYMBOL INDEX (1 symbols across 1 files)
FILE: auth.client.js
function url_base64_decode (line 4) | function url_base64_decode(str) {
Condensed preview — 8 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (9K chars).
[
{
"path": ".gitignore",
"chars": 23,
"preview": ".DS_Store\nnode_modules\n"
},
{
"path": ".jshintrc",
"chars": 656,
"preview": "{\n \"node\": true,\n \"esnext\": true,\n \"bitwise\": true,\n \"curly\": true,\n \"eqeqeq\": true,\n \"immed\": true,\n \"indent\": 2"
},
{
"path": "LICENSE.txt",
"chars": 1121,
"preview": "The MIT License (MIT)\n \nCopyright (c) 2015 Auth0, Inc. <support@auth0.com> (http://auth0.com)\n \nPermission is hereby gra"
},
{
"path": "README.md",
"chars": 1029,
"preview": "## angular-token-auth\n\nExample of Token-based authentication in [AngularJS](http://angularjs.org) with [Express](http://"
},
{
"path": "auth.client.js",
"chars": 2559,
"preview": "var myApp = angular.module('myApp', []);\n\n//this is used to parse the profile\nfunction url_base64_decode(str) {\n var ou"
},
{
"path": "auth.server.js",
"chars": 1432,
"preview": "var express = require('express');\nvar bodyParser = require('body-parser');\n\nvar jwt = require('jsonwebtoken'); //https:"
},
{
"path": "index.html",
"chars": 989,
"preview": "<!DOCTYPE html>\n<html>\n <head>\n <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n <title>Ang"
},
{
"path": "package.json",
"chars": 812,
"preview": "{\n \"name\": \"angular-token-auth\",\n \"version\": \"0.1.0\",\n \"dependencies\": {\n \"body-parser\": \"^1.9.0\",\n \"express\": "
}
]
About this extraction
This page contains the full source code of the auth0/angular-token-auth GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 8 files (8.4 KB), approximately 2.4k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.