This repository has been archived by the owner on Jun 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from AzureAD/dev
Initial release
- Loading branch information
Showing
13 changed files
with
2,494 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#OS junk files | ||
[Tt]humbs.db | ||
*.DS_Store | ||
|
||
#node | ||
*.iml | ||
*.ipr | ||
*.iws | ||
*.tmproj | ||
.project | ||
.settings | ||
.externalToolBuilders | ||
*.swp | ||
node_modules | ||
*~ | ||
/.c9revisions/ | ||
doc/ | ||
build/ | ||
samples/ | ||
|
||
#Visual Studio files | ||
*.[Oo]bj | ||
*.user | ||
*.aps | ||
*.pch | ||
*.vspscc | ||
*.vssscc | ||
*_i.c | ||
*_p.c | ||
*.ncb | ||
*.suo | ||
*.tlb | ||
*.tlh | ||
*.bak | ||
*.[Cc]ache | ||
*.ilk | ||
*.log | ||
*.lib | ||
*.sbr | ||
*.sdf | ||
*.opensdf | ||
*.unsuccessfulbuild | ||
ipch/ | ||
[Oo]bj/ | ||
[Bb]in | ||
[Dd]ebug*/ | ||
[Rr]elease*/ | ||
Ankh.NoLoad | ||
|
||
#MonoDevelop | ||
*.pidb | ||
*.userprefs | ||
|
||
#Tooling | ||
_ReSharper*/ | ||
*.resharper | ||
[Tt]est[Rr]esult* | ||
*.sass-cache | ||
|
||
#Project files | ||
[Bb]uild/ | ||
|
||
#Subversion files | ||
.svn | ||
|
||
# Office Temp Files | ||
~$* | ||
|
||
# vim Temp Files | ||
*~ | ||
|
||
#NuGet | ||
packages/ | ||
*.nupkg | ||
|
||
#bower | ||
bower_components | ||
|
||
#ncrunch | ||
*ncrunch* | ||
*crunch*.local.xml | ||
|
||
# visual studio database projects | ||
*.dbmdl | ||
|
||
#Test files | ||
*.testsettings | ||
|
||
#copied adal | ||
samples/owin/OwinSample/Scripts/adal.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"forin": true, | ||
"freeze": true, | ||
"immed": true, | ||
"indent": 2, | ||
"latedef": true, | ||
"maxparams": false, | ||
"maxdepth": false, | ||
"maxstatements": false, | ||
"maxcomplexity": false, | ||
"multistr" : true, | ||
"newcap": true, | ||
"noarg": true, | ||
"node": true, | ||
"noempty": true, | ||
"nonew": true, | ||
"plusplus": false, | ||
"quotmark": "single", | ||
"regexp": true, | ||
"sub": true, | ||
"strict": true, | ||
"trailing": true, | ||
"undef": true, | ||
"unused": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module.exports = function (grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
clean: ['build/'], | ||
jsdoc: { | ||
dist: { | ||
src: ['lib/*.js'], | ||
options: { | ||
destination: 'doc' | ||
} | ||
} | ||
}, | ||
jshint: { | ||
src: { | ||
options: { | ||
jshintrc: '.jshintrc' | ||
}, | ||
src: ['lib/*.js'] | ||
} | ||
}, | ||
jasmine_node: { | ||
options: { | ||
forceExit: true, | ||
match: '.', | ||
matchall: false, | ||
extensions: 'js', | ||
specNameMatcher: 'spec', | ||
jUnit: { | ||
report: true, | ||
savePath: "./build/reports/jasmine/", | ||
useDotNotation: true, | ||
consolidate: true | ||
} | ||
}, | ||
all: ['tests/unit/spec/'] | ||
} | ||
}); | ||
|
||
// Load the plugin that provides the "uglify" task. | ||
grunt.loadNpmTasks('grunt-jsdoc'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-jasmine-node'); | ||
// uglify task is producing invalid js file | ||
|
||
// jasmine node directly js api | ||
grunt.registerTask('default', ['jshint', 'jasmine_node']); | ||
grunt.registerTask('doc', ['jsdoc']); | ||
grunt.registerTask('minify', ['uglify']); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,174 @@ | ||
azure-activedirectory-library-for-js | ||
Active Directory Authentication Library (ADAL) for JavaScript | ||
==================================== | ||
|
||
Active Directory Authentication Library for JavaScript (ADAL JS) helps you to use Azure AD for handling authentication in your single page applications. | ||
This preview is optimized for working together with AngularJS. | ||
|
||
## The Library | ||
|
||
This is an early developer preview, released for the purpose of eliciting feedback. | ||
The current version is **0.0.1**. | ||
|
||
You have multiple ways of getting ADAL JS: | ||
|
||
Via CDN: | ||
|
||
<!-- Latest compiled and minified JavaScript --> | ||
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/0.0.1/js/adal.min.js"></script> | ||
|
||
|
||
Via Bower: | ||
|
||
$ bower install adal | ||
|
||
The source is [here](https://raw.githubusercontent.com/AzureAD/azure-activedirectory-library-for-js/dev/lib/adal.js?token=ACGxhMoqqbpA5-DApz4r-322ueaIyLBIks5UUotnwA%3D%3D). | ||
|
||
## Samples, tests and documentation | ||
|
||
For a sample demonstrating basic usage of ADAL JS please refer to [this repo](https://github.com/AzureADSamples/SinglePageApp-DotNet). | ||
|
||
**To run tests** | ||
|
||
npm install | ||
bower install | ||
npm test | ||
// angular tests | ||
karma start | ||
|
||
Karma as test runner: | ||
You need to install the karma command line. | ||
|
||
npm install -g karma | ||
npm install -g karma-cli | ||
|
||
|
||
**documentation generation** | ||
Install grunt; call | ||
|
||
grunt doc | ||
|
||
|
||
|
||
**Quick usage guide** | ||
|
||
Below you can find a quick reference for the most common operations you need to perform to use adal js. | ||
|
||
1- Include references to angular.js libraries and adal.js in your main app page. | ||
2- include a reference to adal module | ||
```js | ||
var app = angular.module('demoApp', ['ngRoute', 'AdalAngular']); | ||
``` | ||
3- Initialize adal with the AAD app coordinates at app config time | ||
```js | ||
// endpoint to resource mapping(optional) | ||
var endpoints = { | ||
"https://yourhost/api": "b6a68585-5287-45b2-ba82-383ba1f60932", | ||
}; | ||
adalAuthenticationServiceProvider.init( | ||
{ | ||
// Config to specify endpoints and similar for your app | ||
tenant: "52d4b072-9470-49fb-8721-bc3a1c9912a1", | ||
clientId: "e9a5a8b6-8af7-4719-9821-0deef255f68e", | ||
instance: "https://login.windows-ppe.net/", | ||
//localLoginUrl: "/login", // optional | ||
//redirectUri : "your site", optional | ||
endpoints: endpoints // optional | ||
}, | ||
$httpProvider // pass http provider to inject request interceptor to attach tokens | ||
); | ||
``` | ||
4- Define which routes you want to secure via adal - by adding `requireADLogin: true` to their definition | ||
```js | ||
$routeProvider. | ||
when("/todoList", { | ||
controller: "todoListController", | ||
templateUrl: "/App/Views/todoList.html", | ||
requireADLogin: true | ||
}); | ||
|
||
``` | ||
5- Any service invocation code you might have will remain unchanged. Adal's interceptor will automatically add tokens for every outgoing call. | ||
|
||
***Optional*** | ||
6- If you so choose, in addition (or substitution) to route level protection you can add explicit login/logout UX elements. Furthermore, you can access properties of the currently signed in user directly form JavaScript (via userInfo and userInfo.profile): | ||
```html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Angular Adal Sample</title> | ||
</head> | ||
<body ng-app="adalDemo" ng-controller="homeController" ng-init="hmCtl.init()"> | ||
<a href="#">Home</a> | ||
<a href="#/todoList">ToDo List</a> | ||
|
||
|
||
<!--These links are added to manage login/logout--> | ||
<div data-ng-model="userInfo"> | ||
<span data-ng-hide="!userInfo.isAuthenticated">Welcome {{userInfo.userName}} </span> | ||
<button data-ng-hide="!userInfo.isAuthenticated" data-ng-click="logout()">Logout</button> | ||
<button data-ng-hide="userInfo.isAuthenticated" data-ng-click="login()">Login</button> | ||
|
||
<div> | ||
{{userInfo.loginError}} | ||
</div> | ||
<div> | ||
{{testMessage}} | ||
</div> | ||
</div> | ||
<div ng-view> | ||
Your view will appear here. | ||
</div> | ||
|
||
<script src="/Scripts/angular.min.js"></script> | ||
<script src="/Scripts/angular-route.min.js"></script> | ||
<script src="/Scripts/adal.js"></script> | ||
<script src="App/Scripts/app.js"></script> | ||
<script src="App/Scripts/homeController.js"></script> | ||
<script src="App/Scripts/todoDetailController.js"></script> | ||
<script src="App/Scripts/todoListController.js"></script> | ||
<script src="App/Scripts/todoService.js"></script> | ||
</body> | ||
</html> | ||
``` | ||
7- You have full control on how to trigger sign in, sign out and how to deal with errors: | ||
|
||
```js | ||
'use strict'; | ||
app.controller('homeController', ['$scope', '$location', 'adalAuthenticationService', function ($scope, $location, adalAuthenticationService) { | ||
// this is referencing adal module to do login | ||
|
||
//userInfo is defined at the $rootscope with adalAngular module | ||
$scope.testMessage = ""; | ||
$scope.init = function () { | ||
$scope.testMessage = ""; | ||
}; | ||
|
||
$scope.logout = function () { | ||
adalAuthenticationService.logOut(); | ||
}; | ||
|
||
$scope.login = function () { | ||
adalAuthenticationService.login(); | ||
}; | ||
|
||
// optional | ||
$scope.$on("adal:loginSuccess", function () { | ||
$scope.testMessage = "loginSuccess"; | ||
}); | ||
|
||
// optional | ||
$scope.$on("adal:loginFailure", function () { | ||
$scope.testMessage = "loginFailure"; | ||
$location.path("/login"); | ||
}); | ||
|
||
// optional | ||
$scope.$on("adal:notAuthorized", function (event, rejection, forResource) { | ||
$scope.testMessage = "It is not Authorized for resource:" + forResource; | ||
}); | ||
|
||
}]); | ||
|
||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "adalAngular", | ||
"version": "0.0.1", | ||
"main": "./lib/adal.js", | ||
"description": "Windows Azure Active Directory Client Library for js", | ||
"licenses": [ | ||
{ | ||
"type": "Apache 2.0", | ||
"url": "http://www.apache.org/licenses/LICENSE-2.0" | ||
} | ||
], | ||
"ignore": [ | ||
"coffee", | ||
"coverage", | ||
"js", | ||
"node_modules", | ||
"tests", | ||
"templates", | ||
"Gruntfile.js", | ||
"package.json", | ||
".gitignore" | ||
], | ||
"dependencies": { | ||
"angular": "*" | ||
}, | ||
"devDependencies": { | ||
"angular-mocks": "~1.2.16", | ||
"angular-route": "~1.2.26", | ||
"jasmine": "2.0.0", | ||
"angular-resource": "~1.2.26" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.