1
- // Authors:
2
- // Shane Oatman https://github.com/shoatman
3
- // Sunil Bandla https://github.com/sunilbandla
4
- // Daniel Dobalian https://github.com/danieldobalian
5
-
6
- var express = require ( "express" ) ;
7
- var morgan = require ( "morgan" ) ;
8
- var passport = require ( "passport" ) ;
9
- var BearerStrategy = require ( 'passport-azure-ad' ) . BearerStrategy ;
10
-
11
- // TODO: Update the first 3 variables
12
- var clientID = "93733604-cc77-4a3c-a604-87084dd55348" ;
13
- var b2cDomainHost = "fabrikamb2c.b2clogin.com" ;
14
- var tenantIdGuid = "775527ff-9a37-4307-8b3d-cc311f58d925" ;
15
- var policyName = "B2C_1_SUSI" ;
16
-
17
- var options = {
18
- identityMetadata : "https://" + b2cDomainHost + "/" + tenantIdGuid + "/" + policyName + "/v2.0/.well-known/openid-configuration/" ,
19
- clientID : clientID ,
20
- policyName : policyName ,
21
- isB2C : true ,
22
- validateIssuer : false ,
23
- loggingLevel : 'info' ,
24
- loggingNoPII : false ,
25
- passReqToCallback : false
26
- } ;
27
-
28
- var bearerStrategy = new BearerStrategy ( options ,
29
- function ( token , done ) {
30
- // Send user info using the second argument
31
- done ( null , { } , token ) ;
32
- }
33
- ) ;
34
-
35
- var app = express ( ) ;
36
- app . use ( morgan ( 'dev' ) ) ;
37
-
38
- app . use ( passport . initialize ( ) ) ;
39
- passport . use ( bearerStrategy ) ;
40
-
41
- app . use ( function ( req , res , next ) {
42
- res . header ( "Access-Control-Allow-Origin" , "*" ) ;
43
- res . header ( "Access-Control-Allow-Headers" , "Authorization, Origin, X-Requested-With, Content-Type, Accept" ) ;
44
- next ( ) ;
45
- } ) ;
46
-
47
- app . get ( "/hello" ,
48
- passport . authenticate ( 'oauth-bearer' , { session : false } ) ,
49
- function ( req , res ) {
50
- var claims = req . authInfo ;
51
- console . log ( 'User info: ' , req . user ) ;
52
- console . log ( 'Validated claims: ' , claims ) ;
53
-
54
- if ( claims [ 'scp' ] . split ( " " ) . indexOf ( "demo.read" ) >= 0 ) {
55
- // Service relies on the name claim.
56
- res . status ( 200 ) . json ( { 'name' : claims [ 'name' ] } ) ;
57
- } else {
58
- console . log ( "Invalid Scope, 403" ) ;
59
- res . status ( 403 ) . json ( { 'error' : 'insufficient_scope' } ) ;
60
- }
61
- }
62
- ) ;
63
-
64
- var port = process . env . PORT || 5000 ;
65
- app . listen ( port , function ( ) {
66
- console . log ( "Listening on port " + port ) ;
1
+ // Authors:
2
+ // Shane Oatman https://github.com/shoatman
3
+ // Sunil Bandla https://github.com/sunilbandla
4
+ // Daniel Dobalian https://github.com/danieldobalian
5
+
6
+ var express = require ( "express" ) ;
7
+ var morgan = require ( "morgan" ) ;
8
+ var passport = require ( "passport" ) ;
9
+ var BearerStrategy = require ( 'passport-azure-ad' ) . BearerStrategy ;
10
+
11
+ // TODO: Update the first 3 variables
12
+ var clientID = "93733604-cc77-4a3c-a604-87084dd55348" ;
13
+ var b2cDomainHost = "fabrikamb2c.b2clogin.com" ;
14
+ var tenantIdGuid = "775527ff-9a37-4307-8b3d-cc311f58d925" ;
15
+ var policyName = "B2C_1_SUSI" ;
16
+ var options = {
17
+ identityMetadata : "https://" + b2cDomainHost + "/" + tenantIdGuid + "/" + policyName + "/v2.0/.well-known/openid-configuration/" ,
18
+
19
+ clientID : clientID ,
20
+ policyName : policyName ,
21
+ isB2C : true ,
22
+ validateIssuer : false ,
23
+ loggingLevel : 'info' ,
24
+ loggingNoPII : false ,
25
+ passReqToCallback : false
26
+ } ;
27
+
28
+ var bearerStrategy = new BearerStrategy ( options ,
29
+ function ( token , done ) {
30
+ // Send user info using the second argument
31
+ done ( null , { } , token ) ;
32
+ }
33
+ ) ;
34
+
35
+ var app = express ( ) ;
36
+ app . use ( morgan ( 'dev' ) ) ;
37
+
38
+ app . use ( passport . initialize ( ) ) ;
39
+ passport . use ( bearerStrategy ) ;
40
+
41
+ app . use ( function ( req , res , next ) {
42
+ res . header ( "Access-Control-Allow-Origin" , "*" ) ;
43
+ res . header ( "Access-Control-Allow-Headers" , "Authorization, Origin, X-Requested-With, Content-Type, Accept" ) ;
44
+ next ( ) ;
45
+ } ) ;
46
+
47
+ app . get ( "/hello" ,
48
+ passport . authenticate ( 'oauth-bearer' , { session : false } ) ,
49
+ function ( req , res ) {
50
+ var claims = req . authInfo ;
51
+ console . log ( 'User info: ' , req . user ) ;
52
+ console . log ( 'Validated claims: ' , claims ) ;
53
+
54
+ if ( claims [ 'scp' ] . split ( " " ) . indexOf ( "demo.read" ) >= 0 ) {
55
+ // Service relies on the name claim.
56
+ res . status ( 200 ) . json ( { 'name' : claims [ 'name' ] } ) ;
57
+ } else {
58
+ console . log ( "Invalid Scope, 403" ) ;
59
+ res . status ( 403 ) . json ( { 'error' : 'insufficient_scope' } ) ;
60
+ }
61
+ }
62
+ ) ;
63
+
64
+ var port = process . env . PORT || 5000 ;
65
+ app . listen ( port , function ( ) {
66
+ console . log ( "Listening on port " + port ) ;
67
67
} ) ;
0 commit comments