@@ -4,11 +4,14 @@ const passport = require('passport');
44const config = require ( './config.json' ) ;
55const todolist = require ( './todolist' ) ;
66const cors = require ( 'cors' ) ;
7- const BearerStrategy = require ( 'passport-azure-ad' ) . BearerStrategy ;
87
8+ //<ms_docref_import_azuread_lib>
9+ const BearerStrategy = require ( 'passport-azure-ad' ) . BearerStrategy ;
10+ //</ms_docref_import_azuread_lib>
911
1012global . global_todos = [ ] ;
1113
14+ //<ms_docref_azureadb2c_options>
1215const options = {
1316 identityMetadata : `https://${ config . credentials . tenantName } .b2clogin.com/${ config . credentials . tenantName } .onmicrosoft.com/${ config . policies . policyName } /${ config . metadata . version } /${ config . metadata . discovery } ` ,
1417 clientID : config . credentials . clientID ,
@@ -20,12 +23,15 @@ const options = {
2023 passReqToCallback : config . settings . passReqToCallback
2124}
2225
26+ //</ms_docref_azureadb2c_options>
27+
28+ //<ms_docref_init_azuread_lib>
2329const bearerStrategy = new BearerStrategy ( options , ( token , done ) => {
2430 // Send user info using the second argument
2531 done ( null , { } , token ) ;
2632 }
2733) ;
28-
34+ //</ms_docref_init_azuread_lib>
2935const app = express ( ) ;
3036
3137app . use ( express . json ( ) ) ;
@@ -44,7 +50,8 @@ passport.use(bearerStrategy);
4450// To do list endpoints
4551app . use ( '/api/todolist' , todolist ) ;
4652
47- // API endpoint
53+ //<ms_docref_protected_api_endpoint>
54+ // API endpoint, one must present a bearer accessToken to access this endpoint
4855app . get ( '/hello' ,
4956 passport . authenticate ( 'oauth-bearer' , { session : false } ) ,
5057 ( req , res ) => {
@@ -55,9 +62,12 @@ app.get('/hello',
5562 res . status ( 200 ) . json ( { 'name' : req . authInfo [ 'name' ] } ) ;
5663 }
5764) ;
65+ //</ms_docref_protected_api_endpoint>
5866
59- // API anonymous endpoint
67+ //<ms_docref_anonymous_api_endpoint>
68+ // API anonymous endpoint, returns a date to the caller.
6069app . get ( '/public' , ( req , res ) => res . send ( { 'date' : new Date ( ) } ) ) ;
70+ //</ms_docref_anonymous_api_endpoint>
6171
6272const port = process . env . PORT || 5000 ;
6373
0 commit comments