Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit ea853dd

Browse files
committed
docs(cb-azure-ad-auth): Add new cookbook
1 parent 61b13c1 commit ea853dd

20 files changed

+633
-13
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path='../_protractor/e2e.d.ts' />
2+
'use strict';
3+
describe('Azure AD Auth E2E tests', function () {
4+
5+
let expectedMsg = 'Simple app demonstrates';
6+
7+
beforeEach(function () {
8+
browser.get('');
9+
});
10+
11+
it(`should display: ${expectedMsg}`, function () {
12+
expect(element(by.css('p')).getText()).toContain(expectedMsg);
13+
});
14+
15+
});

public/docs/_examples/cb-azure-ad-auth/ts/.gitignore

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Component } from '@angular/core';
2+
@Component({
3+
selector: 'app',
4+
template: `
5+
<a [routerLink]="['']">About</a> | <a [routerLink]="['login']">Login</a> | <a [routerLink]="['status']">Status</a> <br/>
6+
<router-outlet></router-outlet>`
7+
})
8+
9+
export class AppComponent { }
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// #docregion
2+
import { NgModule } from '@angular/core';
3+
import { HttpModule } from '@angular/http';
4+
import { BrowserModule } from '@angular/platform-browser';
5+
import { routing } from './app.routing';
6+
import { AppComponent } from './app.component';
7+
8+
import { HomeComponent } from './home/home.component';
9+
import { LoginComponent } from './login/login.component';
10+
import { StatusComponent } from './status/status.component';
11+
12+
import { AzureADServiceConstants } from './ngAuth/authenticators/AzureADServiceConstants';
13+
import { AzureADAuthService } from './ngAuth/authenticators/AzureADAuthService';
14+
import { AuthenticatedHttpService } from './ngAuth/AuthenticatedHttpService';
15+
16+
import { serviceConstants } from './authsettings.config';
17+
18+
let authenticator = new AzureADAuthService(serviceConstants);
19+
20+
@NgModule({
21+
providers: [
22+
AuthenticatedHttpService,
23+
{
24+
provide: AzureADAuthService,
25+
useValue: authenticator
26+
}],
27+
imports: [
28+
routing,
29+
BrowserModule,
30+
HttpModule
31+
],
32+
declarations: [
33+
AppComponent,
34+
HomeComponent,
35+
LoginComponent,
36+
StatusComponent
37+
],
38+
bootstrap: [AppComponent]
39+
})
40+
export class AppModule { }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// #docregion
2+
import { ModuleWithProviders } from '@angular/core';
3+
import { Routes, RouterModule } from '@angular/router';
4+
import { LoginComponent } from './login/login.component';
5+
import {HomeComponent} from './home/home.component';
6+
import { StatusComponent } from './status/status.component';
7+
8+
export const routes: Routes = [
9+
{ path: '', component: HomeComponent },
10+
{ path: 'login', component: LoginComponent },
11+
{ path: 'status', component: StatusComponent },
12+
];
13+
export const routing: ModuleWithProviders = RouterModule.forRoot(routes);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {AzureADServiceConstants} from './ngAuth/authenticators/AzureADServiceConstants';
2+
3+
export const serviceConstants: AzureADServiceConstants = new AzureADServiceConstants(
4+
"e176a5f1-596e-44c9-91cb-46de9bb96ee1",
5+
"angularad.onmicrosoft.com",
6+
"http://localhost:3000/status",
7+
"https://graph.windows.net"
8+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Component } from '@angular/core';
2+
import { Inject, Injectable } from '@angular/core';
3+
4+
@Component({
5+
template:`
6+
Simple app demonstrates logging into AzureAD and running a command against the Azure AD graph. <br/>
7+
Click the login tab to login, and status tab to view your login status.
8+
`
9+
})
10+
export class HomeComponent { }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// #docregion
2+
import { Component, Inject } from '@angular/core';
3+
import { Router } from '@angular/router';
4+
5+
import {AzureADAuthService} from '../ngAuth/authenticators/AzureADAuthService';
6+
7+
@Component({
8+
template: `
9+
<button (click)="logIn()">
10+
Sign In
11+
</button>`
12+
})
13+
14+
export class LoginComponent {
15+
constructor(
16+
@Inject(AzureADAuthService) private _authService: AzureADAuthService,
17+
private _router: Router) { }
18+
19+
logIn() {
20+
this._authService.logIn("/");
21+
}
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2+
import {AppModule} from './app.module';
3+
platformBrowserDynamic().bootstrapModule(AppModule);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// #docregion
2+
import { Injectable, Inject } from '@angular/core';
3+
import { Http, Headers, Response } from '@angular/http';
4+
import { AzureADAuthService } from './authenticators/AzureADAuthService';
5+
import { Observable, Subscriber } from 'rxjs';
6+
7+
@Injectable()
8+
export class AuthenticatedHttpService {
9+
private _authenticator: AzureADAuthService;
10+
private _http: Http;
11+
constructor( @Inject(Http) http: Http, @Inject(AzureADAuthService) authenticator: AzureADAuthService) {
12+
this._authenticator = authenticator;
13+
this._http = http;
14+
}
15+
16+
createAuthorizationHeader(headers: Headers) {
17+
headers.append('Authorization', 'Bearer ' + this._authenticator.getAccessToken());
18+
}
19+
20+
get(url: string) {
21+
let headers = new Headers();
22+
this.createAuthorizationHeader(headers);
23+
return this._http.get(url, { headers: headers });
24+
}
25+
26+
post(url: string, data: any) {
27+
let headers = new Headers();
28+
this.createAuthorizationHeader(headers);
29+
return this._http.post(url, data, {
30+
headers: headers,
31+
});
32+
}
33+
}

0 commit comments

Comments
 (0)