@@ -4,11 +4,14 @@ const passport = require('passport');
4
4
const config = require ( './config.json' ) ;
5
5
const todolist = require ( './todolist' ) ;
6
6
const cors = require ( 'cors' ) ;
7
- const BearerStrategy = require ( 'passport-azure-ad' ) . BearerStrategy ;
8
7
8
+ //<ms_docref_import_azuread_lib>
9
+ const BearerStrategy = require ( 'passport-azure-ad' ) . BearerStrategy ;
10
+ //</ms_docref_import_azuread_lib>
9
11
10
12
global . global_todos = [ ] ;
11
13
14
+ //<ms_docref_azureadb2c_options>
12
15
const options = {
13
16
identityMetadata : `https://${ config . credentials . tenantName } .b2clogin.com/${ config . credentials . tenantName } .onmicrosoft.com/${ config . policies . policyName } /${ config . metadata . version } /${ config . metadata . discovery } ` ,
14
17
clientID : config . credentials . clientID ,
@@ -20,12 +23,15 @@ const options = {
20
23
passReqToCallback : config . settings . passReqToCallback
21
24
}
22
25
26
+ //</ms_docref_azureadb2c_options>
27
+
28
+ //<ms_docref_init_azuread_lib>
23
29
const bearerStrategy = new BearerStrategy ( options , ( token , done ) => {
24
30
// Send user info using the second argument
25
31
done ( null , { } , token ) ;
26
32
}
27
33
) ;
28
-
34
+ //</ms_docref_init_azuread_lib>
29
35
const app = express ( ) ;
30
36
31
37
app . use ( express . json ( ) ) ;
@@ -44,7 +50,8 @@ passport.use(bearerStrategy);
44
50
// To do list endpoints
45
51
app . use ( '/api/todolist' , todolist ) ;
46
52
47
- // API endpoint
53
+ //<ms_docref_protected_api_endpoint>
54
+ // API endpoint, one must present a bearer accessToken to access this endpoint
48
55
app . get ( '/hello' ,
49
56
passport . authenticate ( 'oauth-bearer' , { session : false } ) ,
50
57
( req , res ) => {
@@ -55,9 +62,12 @@ app.get('/hello',
55
62
res . status ( 200 ) . json ( { 'name' : req . authInfo [ 'name' ] } ) ;
56
63
}
57
64
) ;
65
+ //</ms_docref_protected_api_endpoint>
58
66
59
- // API anonymous endpoint
67
+ //<ms_docref_anonymous_api_endpoint>
68
+ // API anonymous endpoint, returns a date to the caller.
60
69
app . get ( '/public' , ( req , res ) => res . send ( { 'date' : new Date ( ) } ) ) ;
70
+ //</ms_docref_anonymous_api_endpoint>
61
71
62
72
const port = process . env . PORT || 5000 ;
63
73
0 commit comments