Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
b462206
Fixed build error and acquire token function
sureshchahal Aug 1, 2016
7f38f4b
allback when access token is received
sureshchahal Aug 4, 2016
18a90f0
Handled error during acquire token
sureshchahal Aug 8, 2016
e76607e
Added Http extension for acquring token for CORS API
sureshchahal Aug 11, 2016
0ac499e
Fixed complie errors
sureshchahal Aug 22, 2016
ee0cd13
AuthHttp can take RequestOptions in http requests
jdkb123 Aug 28, 2016
2a86e4d
Merge pull request #1 from jdkb123/patch-1
sureshchahal Aug 29, 2016
dcdce45
Update README.md
sureshchahal Sep 9, 2016
9cdb7b3
Only check for authenticated user only if backend API is configured i…
sureshchahal Sep 21, 2016
eb2bf16
Provided Put, Patch and Head methods
sureshchahal Sep 29, 2016
f661f40
Released as separate package ng2-adal
sureshchahal Sep 29, 2016
b418c30
body was ignored in Put, Post and Patch
fume Oct 25, 2016
7b302e3
Merge pull request #2 from fume/master
sureshchahal Oct 27, 2016
7ddc85a
upgraded to angular2
sureshchahal Oct 31, 2016
f667c85
Merge branch 'master' of https://github.com/sureshchahal/angular2-adal
sureshchahal Oct 31, 2016
1febba9
upgraded version for publish
sureshchahal Oct 31, 2016
31a0429
Fixed for Angular2
sureshchahal Nov 1, 2016
6a9ea40
removed debugger
fume Nov 5, 2016
20354d0
Merge pull request #7 from fume/issue-6
sureshchahal Nov 5, 2016
6fce6f8
exposing via NgModule
fume Nov 5, 2016
207a465
Added skipLibCheck to tsconfig
fume Nov 5, 2016
0c229cc
Merge branch 'master' into issue-8
fume Nov 5, 2016
e2a654c
Merge pull request #9 from fume/issue-8
sureshchahal Nov 7, 2016
23ec861
Upgraded version after modules
sureshchahal Nov 9, 2016
f6abafe
Upgraded to 0.2.5
sureshchahal Nov 9, 2016
9eeb7f0
Typo in imports. adal.service and authHttp.service do not work on Ubuntu
pkalinnikov Nov 30, 2016
89bdd11
Merge pull request #14 from pkalinnikov/master
sureshchahal Dec 2, 2016
6749aef
Renamed adal to adal-angular to let webpack build run without aliases
Dec 21, 2016
d173544
Fixed webpack warnings "There is another module with an equal name wh…
Dec 21, 2016
26e2d81
Updated gulp-typescript to use TypeScript 2.x and fix syntax errors d…
Dec 21, 2016
6f5ecc1
Merge pull request #16 from DarkXaHTeP/master
sureshchahal Dec 25, 2016
4a76078
Replaced typings with predefined typescript types for es2015 and brow…
Dec 28, 2016
2b993a2
Updated angular-adal
Dec 28, 2016
6c5fb1d
Removed postinstall for typings
Dec 28, 2016
58ae823
Removed parts of adal typing in src/adal-angular that are not needed …
Dec 28, 2016
79feaa6
Merge pull request #18 from DarkXaHTeP/master
sureshchahal Dec 28, 2016
64d07fe
Updated version to 0.2.6
Dec 28, 2016
07ab219
Update README.md
sureshchahal Jan 19, 2017
bc0306d
fixing issue #19 and #20
Jan 23, 2017
619733b
Fixed issue with 'this' not referencing AdalService as expected. Also…
cbrianball Feb 6, 2017
7c789e8
Merge pull request #27 from cbrianball/bug/AdalService.acquireToken-o…
sureshchahal Feb 16, 2017
6a388ab
acquireToken(resource) now returns Observable<string>, so Typescript …
corfor Feb 23, 2017
713ddc3
fixed sendRequest(url, options) to return Observable<string>
corfor Feb 23, 2017
9c692de
fixed runtime bug found by @jbarr33
corfor Mar 6, 2017
5dcafa5
Merge branch 'develop'
corfor Mar 6, 2017
78ceb6b
fixed runtime bug found by @jbarr33
corfor Mar 6, 2017
a55f65e
Expose ability to refresh the data from cache
mkelan Mar 19, 2017
3b52a61
Merge pull request #30 from corfor/master
sureshchahal Mar 20, 2017
5aa14cb
Merged and published latest pull
Mar 20, 2017
dae85b8
Merge pull request #35 from mazhisai/master
sureshchahal Mar 21, 2017
9209b21
Updated version after publishing 0.3.0 version to npm
Mar 21, 2017
da9ed22
Update authHttp.service.ts
Cyberdada Apr 27, 2017
4242c5c
changed import from rxjs
Cyberdada Apr 27, 2017
1f18d01
Merge pull request #39 from Cyberdada/master
sureshchahal Apr 27, 2017
8f660e8
Added check for id_token to fix the issue where token refreshes in th…
jjbrunton May 17, 2017
c4058d8
Merge pull request #1 from Dootrix/bug/token-refresh
cargowire May 17, 2017
78e2047
Merge pull request #45 from Dootrix/master
sureshchahal May 17, 2017
f5c66ed
Reverted pull from Cyberdada , it broke build
May 17, 2017
d164546
Update adal.service.ts
Cyberdada May 24, 2017
f3275ca
Update authHttp.service.ts
Cyberdada May 24, 2017
5092987
Update core.ts
Cyberdada May 24, 2017
a0eba5f
Update package.json
Cyberdada May 24, 2017
4fc2c47
Update bundle.js
Cyberdada May 24, 2017
35015ec
Update authHttp.service.ts
Cyberdada May 24, 2017
3be32db
Merge branch 'master' into master
sureshchahal May 24, 2017
5c2ec5e
Merge pull request #48 from Cyberdada/master
sureshchahal May 24, 2017
5389051
Separate repo for ng2 and ng4
sureshchahal May 24, 2017
d5b8ca1
Published Angular 4 version
May 31, 2017
1323541
Don´t log errors to console
ericivarsson Jun 27, 2017
4c1ba8c
Merge pull request #1 from sureshchahal/master
rjwijnen Jun 28, 2017
b95e6a5
Fix Throw error in AuthHttp.service
Jun 28, 2017
9a6b8f6
Merge pull request #53 from ericivarsson/patch-1
sureshchahal Jun 28, 2017
75dcf0f
Merge pull request #54 from rjwijnen/master
sureshchahal Jun 28, 2017
b63513d
Fix reference to this in getUser error
aciccarello Aug 8, 2017
2c94172
Eliminate dead code in adal.service
aciccarello Aug 8, 2017
a0cc0e6
Fix Typescript >= 2.4.1 compilation error described on issue #64
nelsonmorais Sep 13, 2017
9be3a23
Merge pull request #61 from aciccarello/patch-3
sureshchahal Sep 16, 2017
67f3375
Merge pull request #63 from aciccarello/patch-4
sureshchahal Sep 16, 2017
ab2629c
Merge branch 'master' into patch-1
sureshchahal Sep 16, 2017
9774374
Merge pull request #65 from nelsonmorais/patch-1
sureshchahal Sep 16, 2017
b8bbbe6
Updated package version
Sep 17, 2017
b52db0f
Update README.md
sureshchahal Sep 17, 2017
0699d98
Update README.md
sureshchahal Sep 17, 2017
e2904fa
Update package.json
sureshchahal Sep 17, 2017
f5a913e
Update readme
Sep 27, 2017
c884fde
Merge pull request #69 from claudiuconstantin/patch-1
sureshchahal Sep 29, 2017
d04f513
Updated README with the new example URL
ranveeraggarwal Oct 11, 2017
266e93e
Merge pull request #70 from ranveeraggarwal/update-example-url
sureshchahal Oct 22, 2017
f535eb7
Merge pull request #2 from sureshchahal/master
rjwijnen Nov 28, 2017
31da0c1
Update package.json to angular 5
Nov 28, 2017
45846df
Update add interceptor instead of AuthHttp
Nov 30, 2017
010ff5a
Updated Readme
Nov 30, 2017
46cfd83
this was undefined in getUser error handler
wvanderdeijl Jan 2, 2018
046e977
Add authenticationStatus observable to OAuthData
Jan 12, 2018
0a738c7
Make authentication status observable on oauthData
Jan 12, 2018
5559c1d
remove package lock
Jan 30, 2018
29edbb6
Remove handle error since it is not doing anything
Jan 30, 2018
3698cd5
Add observable.throw
Mar 26, 2018
4185a53
Merge pull request #84 from straach/merge_back_to_fork_origin
sureshchahal Aug 4, 2022
dfbc718
Merge pull request #80 from wvanderdeijl/getUser-this-undefined
sureshchahal Aug 4, 2022
33ef768
Merge pull request #77 from rjwijnen/master
sureshchahal Aug 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

To do authentication against Microsoft Windows Azure AD, using the Microsoft ADAL library underneath. Note this library is extracted from the <b>adal-angular</b> package.

NPM Package: https://www.npmjs.com/package/angular2-adal
This also provide AuthHttp class, which actually gets token in background for external webapis.

NPM Package:

Example and guideline: https://github.com/alenny/angular2-adal-example
5 changes: 5 additions & 0 deletions gulp/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const bundleConfig = {
main: 'index.js',
defaultExtension: 'js'
},

'@angular/http' : {
main: 'index.js',
defaultExtension: 'js'
},
rxjs: {
main: 'Rx.js',
defaultExtension: 'js'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@angular/compiler": "^2.0.0-rc.1",
"@angular/core": "^2.0.0-rc.1",
"@angular/platform-browser": "^2.0.0-rc.1",
"@angular/http": "^2.0.0-rc.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
Expand Down
163 changes: 163 additions & 0 deletions src/adal/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
declare module 'adal' {
export function inject(config: adal.Config): adal.AuthenticationContext;
}

declare namespace adal {

interface Config {
clientId: string,
anonymousEndpoints?: any,
cacheLocation?: string,
correlationId?: string,
displayCall?: (urlNavigate: string) => any,
endpoints?: any, // If you need to send CORS api requests.
expireOffsetSeconds?: number,
extraQueryParameter?: string,
instance?: string,
localLoginUrl?: string,
loginResource?: string,
postLogoutRedirectUri?: string,
redirectUri?: string,
state?: string,
tenant?: string
}

interface User {
userName: string,
profile?: any
}

interface RequestInfo {
valid: boolean,
parameters: any,
stateMatch: boolean,
stateResponse: string,
requestType: string
}

interface AuthenticationContextStatic {
new (config: Config): AuthenticationContext;
}

interface AuthenticationContext {

REQUEST_TYPE: {
LOGIN: string,
RENEW_TOKEN: string,
UNKNOWN: string
};
instance: string;
config: Config;

/**
* Gets initial Idtoken for the app backend
* Saves the resulting Idtoken in localStorage.
*/
login(): void;
loginInProgress(): boolean;

/**
* Gets token for the specified resource from local storage cache
* @param {string} resource A URI that identifies the resource for which the token is valid.
* @returns {string} token if exists and not expired or null
*/
getCachedToken(resource: string): string;

/**
* Retrieves and parse idToken from localstorage
* @returns {User} user object
*/
getCachedUser(): User;

registerCallback(expectedState: string, resource: string, callback: (message: string, token: string) => any): void;

/**
* Acquire token from cache if not expired and available. Acquires token from iframe if expired.
* @param {string} resource ResourceUri identifying the target resource
* @param {requestCallback} callback
*/
acquireToken(resource: string, callback: (message: string, token: string) => any): void;

/**
* Redirect the Browser to Azure AD Authorization endpoint
* @param {string} urlNavigate The authorization request url
*/
promptUser(urlNavigate: string): void;

/**
* Clear cache items.
*/
clearCache(): void;

/**
* Clear cache items for a resource.
*/
clearCacheForResource(resource: string): void;

/**
* Logout user will redirect page to logout endpoint.
* After logout, it will redirect to post_logout page if provided.
*/
logOut(): void;

/**
* Gets a user profile
* @param {requestCallback} callback - The callback that handles the response.
*/
getUser(callback: (message: string, user?: User) => any): void;

/**
* Checks if hash contains access token or id token or error_description
* @param {string} hash - Hash passed from redirect page
* @returns {Boolean}
*/
isCallback(hash: string): boolean;

/**
* Gets login error
* @returns {string} error message related to login
*/
getLoginError(): string;

/**
* Gets requestInfo from given hash.
* @returns {string} error message related to login
*/
getRequestInfo(hash: string): RequestInfo;

/**
* Saves token from hash that is received from redirect.
*/
saveTokenFromHash(requestInfo: RequestInfo): void;

/**
* Gets resource for given endpoint if mapping is provided with config.
* @param {string} endpoint - API endpoint
* @returns {string} resource for this API endpoint
*/
getResourceForEndpoint(endpoint: string): string;

handleWindowCallback(): void;

callback : any;

_getItem : any;

_renewFailed : any;

CONSTANTS : any;

log(level: number, message: string, error: any): void;
error(message: string, error: any): void;
warn(message: string): void;
info(message: string): void;
verbose(message: string): void;
}

}

interface Window {
AuthenticationContext : any;
callBackMappedToRenewStates : any;
}

3 changes: 2 additions & 1 deletion src/services.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export {AdalService} from './services/adal.service';
export {OAuthData} from './services/oauthdata.model';
export {OAuthData} from './services/oauthdata.model';
export {AuthHttp} from './services/authHttp.service'
53 changes: 41 additions & 12 deletions src/services/adal.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import {Injectable} from '@angular/core';
import 'rxjs/Rx';
import {Observable} from "rxjs/Observable";
import 'rxjs/Observable/bindCallback'
import adalLib = require('adal');
import {OAuthData} from "./oauthdata.model";




@Injectable()
export class AdalService {

Expand Down Expand Up @@ -33,6 +37,8 @@ export class AdalService {
// create instance with given config
this.adalContext = adalLib.inject(configOptions);

window.AuthenticationContext = this.adalContext.constructor;

// loginresource is used to set authenticated status
this.updateDataFromCache(this.adalContext.config.loginResource);
}
Expand Down Expand Up @@ -64,7 +70,30 @@ export class AdalService {
this.adalContext.saveTokenFromHash(requestInfo);
if (requestInfo.requestType === this.adalContext.REQUEST_TYPE.LOGIN) {
this.updateDataFromCache(this.adalContext.config.loginResource);

} else if (requestInfo.requestType === this.adalContext.REQUEST_TYPE.RENEW_TOKEN) {
this.adalContext.callback = window.parent.callBackMappedToRenewStates[requestInfo.stateResponse];
}

if(requestInfo.stateMatch)
{
if (typeof this.adalContext.callback === 'function')
{
if (requestInfo.requestType === this.adalContext.REQUEST_TYPE.RENEW_TOKEN)
{
// Idtoken or Accestoken can be renewed
if (requestInfo.parameters['access_token'])
{
this.adalContext.callback(this.adalContext._getItem(this.adalContext.CONSTANTS.STORAGE.ERROR_DESCRIPTION)
, requestInfo.parameters['access_token']);
}
else if (requestInfo.parameters['error'])
{
this.adalContext.callback(this.adalContext._getItem(this.adalContext.CONSTANTS.STORAGE.ERROR_DESCRIPTION), null);
this.adalContext._renewFailed = true;
}
}
}
}
}
}
Expand All @@ -74,7 +103,7 @@ export class AdalService {
}

public acquireToken(resource: string) {
return Observable.bindCallback(function (cb) {
return Observable.bindCallback((cb) => {
this.adalContext.acquireToken(resource, function (error: string, tokenOut: string) {
if (error) {
this.adalContext.error('Error when acquiring token for resource: ' + resource, error);
Expand All @@ -83,7 +112,7 @@ export class AdalService {
cb(tokenOut);
}
});
});
})();
}

public getUser(): Observable<adal.User> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update the below line
return Observable.bindCallback(function (cb: (u: adal.User) => void) {
to
return Observable.bindCallback((cb: (u: adal.User) => void) => {

as the ts compiler is behaving weirdly with first format and creating a JS of

AdalService.prototype.getUser = function () {
return Observable_1.Observable.bindCallback(function (cb) {
this.adalContext.getUser(function (error, user) {

instead of this

AdalService.prototype.getUser = function () {
    var _this = this;
    return Observable_1.Observable.bindCallback(function (cb) {
        _this.adalContext.getUser(function (error, user) {

which is failing with null reference at this.adalContext.something

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Expand Down Expand Up @@ -115,18 +144,18 @@ export class AdalService {
this.adalContext.verbose(message);
}

public GetResourceForEndpoint(url: string): string
{
return this.adalContext.getResourceForEndpoint(url);
}

private updateDataFromCache(resource: string): void {
let token = this.adalContext.getCachedToken(resource);
this.oauthData.isAuthenticated = token !== null && token.length > 0;
var user = this.adalContext.getCachedUser();
if (user) {
this.oauthData.userName = user.userName;
this.oauthData.profile = user.profile;
this.oauthData.loginError = this.adalContext.getLoginError();
} else {
this.oauthData.userName = '';
this.oauthData.profile = {};
this.oauthData.loginError = '';
}
var user = this.adalContext.getCachedUser() || { userName: '' };
this.oauthData.userName = user.userName;
this.oauthData.profile = user.profile;
this.oauthData.loginError = this.adalContext.getLoginError();

};
}
Loading