@@ -8,26 +8,32 @@ var async = require('async');
8
8
var url = require ( 'url' ) ;
9
9
var jwt = require ( 'jsonwebtoken' ) ;
10
10
var zlib = require ( 'zlib' ) ;
11
+ var pjson = require ( '../../package.json' ) ;
11
12
var MAX_DATA_LENGTH = 65000 ;
13
+ var USER_AGENT = "Microsoft-BotFramework/3.0 (BotBuilder Node.js/" + pjson . version + ")" ;
12
14
var ChatConnector = ( function ( ) {
13
15
function ChatConnector ( settings ) {
14
16
if ( settings === void 0 ) { settings = { } ; }
15
17
this . settings = settings ;
16
18
if ( ! this . settings . endpoint ) {
17
19
this . settings . endpoint = {
18
- refreshEndpoint : 'https://login.microsoftonline.com/common /oauth2/v2.0/token' ,
19
- refreshScope : 'https://graph.microsoft .com/.default' ,
20
- botConnectorOpenIdMetadata : this . settings . openIdMetadata || 'https://api.aps.skype .com/v1/.well-known/openidconfiguration' ,
20
+ refreshEndpoint : 'https://login.microsoftonline.com/botframework.com /oauth2/v2.0/token' ,
21
+ refreshScope : 'https://api.botframework .com/.default' ,
22
+ botConnectorOpenIdMetadata : this . settings . openIdMetadata || 'https://login.botframework .com/v1/.well-known/openidconfiguration' ,
21
23
botConnectorIssuer : 'https://api.botframework.com' ,
22
24
botConnectorAudience : this . settings . appId ,
23
25
msaOpenIdMetadata : 'https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration' ,
24
26
msaIssuer : 'https://sts.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47/' ,
25
27
msaAudience : 'https://graph.microsoft.com' ,
28
+ emulatorOpenIdMetadata : 'https://login.microsoftonline.com/botframework.com/v2.0/.well-known/openid-configuration' ,
29
+ emulatorAudience : 'https://sts.windows.net/d6d49420-f39b-4df7-a1dc-d59a935871db/' ,
30
+ emulatorIssuer : this . settings . appId ,
26
31
stateEndpoint : this . settings . stateEndpoint || 'https://state.botframework.com'
27
32
} ;
28
33
}
29
34
this . botConnectorOpenIdMetadata = new OpenIdMetadata_1 . OpenIdMetadata ( this . settings . endpoint . botConnectorOpenIdMetadata ) ;
30
35
this . msaOpenIdMetadata = new OpenIdMetadata_1 . OpenIdMetadata ( this . settings . endpoint . msaOpenIdMetadata ) ;
36
+ this . emulatorOpenIdMetadata = new OpenIdMetadata_1 . OpenIdMetadata ( this . settings . endpoint . emulatorOpenIdMetadata ) ;
31
37
}
32
38
ChatConnector . prototype . listen = function ( ) {
33
39
var _this = this ;
@@ -71,6 +77,14 @@ var ChatConnector = (function () {
71
77
clockTolerance : 300
72
78
} ;
73
79
}
80
+ else if ( isEmulator && decoded . payload . iss == this . settings . endpoint . emulatorIssuer ) {
81
+ openIdMetadata = this . emulatorOpenIdMetadata ;
82
+ verifyOptions = {
83
+ issuer : this . settings . endpoint . emulatorIssuer ,
84
+ audience : this . settings . endpoint . emulatorAudience ,
85
+ clockTolerance : 300
86
+ } ;
87
+ }
74
88
else {
75
89
openIdMetadata = this . botConnectorOpenIdMetadata ;
76
90
verifyOptions = {
@@ -79,6 +93,12 @@ var ChatConnector = (function () {
79
93
clockTolerance : 300
80
94
} ;
81
95
}
96
+ if ( isEmulator && decoded . payload . appid != this . settings . appId ) {
97
+ logger . error ( 'ChatConnector: receive - invalid token. Requested by unexpected app ID.' ) ;
98
+ res . status ( 403 ) ;
99
+ res . end ( ) ;
100
+ return ;
101
+ }
82
102
openIdMetadata . getKey ( decoded . header . kid , function ( key ) {
83
103
if ( key ) {
84
104
try {
@@ -375,6 +395,7 @@ var ChatConnector = (function () {
375
395
this . authenticatedRequest ( options , function ( err , response , body ) { return cb ( err ) ; } ) ;
376
396
}
377
397
else {
398
+ this . addUserAgent ( options ) ;
378
399
request ( options , function ( err , response , body ) {
379
400
if ( ! err && response . statusCode >= 400 ) {
380
401
var txt = "Request to '" + options . url + "' failed: [" + response . statusCode + "] " + response . statusMessage ;
@@ -459,7 +480,14 @@ var ChatConnector = (function () {
459
480
cb ( null , this . accessToken ) ;
460
481
}
461
482
} ;
483
+ ChatConnector . prototype . addUserAgent = function ( options ) {
484
+ if ( options . headers == null ) {
485
+ options . headers = { } ;
486
+ }
487
+ options . headers [ 'User-Agent' ] = USER_AGENT ;
488
+ } ;
462
489
ChatConnector . prototype . addAccessToken = function ( options , cb ) {
490
+ this . addUserAgent ( options ) ;
463
491
if ( this . settings . appId && this . settings . appPassword ) {
464
492
this . getAccessToken ( function ( err , token ) {
465
493
if ( ! err && token ) {
0 commit comments