forked from microsoft/botbuilder-js
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c76a36d
commit 9fd7081
Showing
9 changed files
with
108 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,4 +69,3 @@ export { | |
RankerTypes, | ||
ServiceType, | ||
} from './qnamaker-interfaces'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
libraries/botframework-connector/src/auth/tokenCredentials.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
import { HttpHeaders, Constants, WebResourceLike, ServiceClientCredentials } from "@azure/core-http"; | ||
|
||
const HeaderConstants = Constants.HeaderConstants; | ||
const DEFAULT_AUTHORIZATION_SCHEME = "Bearer"; | ||
|
||
/** | ||
* A credentials object that uses a token string and a authorzation scheme to authenticate. | ||
*/ | ||
export class TokenCredentials implements ServiceClientCredentials { | ||
token: string; | ||
authorizationScheme: string = DEFAULT_AUTHORIZATION_SCHEME; | ||
|
||
/** | ||
* Creates a new TokenCredentials object. | ||
* | ||
* @constructor | ||
* @param {string} token The token. | ||
* @param {string} [authorizationScheme] The authorization scheme. | ||
*/ | ||
constructor(token: string, authorizationScheme: string = DEFAULT_AUTHORIZATION_SCHEME) { | ||
if (!token) { | ||
throw new Error("token cannot be null or undefined."); | ||
} | ||
this.token = token; | ||
this.authorizationScheme = authorizationScheme; | ||
} | ||
|
||
/** | ||
* Signs a request with the Authentication header. | ||
* | ||
* @param {WebResourceLike} webResource The WebResourceLike to be signed. | ||
* @return {Promise<WebResourceLike>} The signed request object. | ||
*/ | ||
signRequest(webResource: WebResourceLike) { | ||
if (!webResource.headers) webResource.headers = new HttpHeaders(); | ||
webResource.headers.set( | ||
HeaderConstants.AUTHORIZATION, | ||
`${this.authorizationScheme} ${this.token}` | ||
); | ||
return Promise.resolve(webResource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,15 @@ | |
resolved "https://registry.yarnpkg.com/@azure/core-asynciterator-polyfill/-/core-asynciterator-polyfill-1.0.0.tgz#dcccebb88406e5c76e0e1d52e8cc4c43a68b3ee7" | ||
integrity sha512-kmv8CGrPfN9SwMwrkiBK9VTQYxdFQEGe0BmQk+M8io56P9KNzpAxcWE/1fxJj7uouwN4kXF0BHW8DNlgx+wtCg== | ||
|
||
"@azure/core-auth@^1.1.4": | ||
version "1.5.0" | ||
resolved "https://registry.yarnpkg.com/@azure/core-auth/-/core-auth-1.5.0.tgz#a41848c5c31cb3b7c84c409885267d55a2c92e44" | ||
integrity sha512-udzoBuYG1VBoHVohDTrvKjyzel34zt77Bhp7dQntVGGD0ehVq48owENbBG8fIgkHRNUBQH5k1r0hpoMu5L8+kw== | ||
dependencies: | ||
"@azure/abort-controller" "^1.0.0" | ||
"@azure/core-util" "^1.1.0" | ||
tslib "^2.2.0" | ||
|
||
"@azure/core-auth@^1.2.0", "@azure/core-auth@^1.4.0": | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/@azure/core-auth/-/core-auth-1.4.0.tgz#6fa9661c1705857820dbc216df5ba5665ac36a9e" | ||
|
@@ -134,6 +143,14 @@ | |
dependencies: | ||
tslib "^2.0.0" | ||
|
||
"@azure/core-util@^1.1.0": | ||
version "1.6.1" | ||
resolved "https://registry.yarnpkg.com/@azure/core-util/-/core-util-1.6.1.tgz#fea221c4fa43c26543bccf799beb30c1c7878f5a" | ||
integrity sha512-h5taHeySlsV9qxuK64KZxy4iln1BtMYlNt5jbuEFN3UFSAd1EwKg/Gjl5a6tZ/W8t6li3xPnutOx7zbDyXnPmQ== | ||
dependencies: | ||
"@azure/abort-controller" "^1.0.0" | ||
tslib "^2.2.0" | ||
|
||
"@azure/core-util@^1.1.1": | ||
version "1.3.2" | ||
resolved "https://registry.yarnpkg.com/@azure/core-util/-/core-util-1.3.2.tgz#3f8cfda1e87fac0ce84f8c1a42fcd6d2a986632d" | ||
|
@@ -214,6 +231,20 @@ | |
resolved "https://registry.yarnpkg.com/@azure/ms-rest-azure-env/-/ms-rest-azure-env-2.0.0.tgz#45809f89763a480924e21d3c620cd40866771625" | ||
integrity sha512-dG76W7ElfLi+fbTjnZVGj+M9e0BIEJmRxU6fHaUQ12bZBe8EJKYb2GV50YWNaP2uJiVQ5+7nXEVj1VN1UQtaEw== | ||
|
||
"@azure/ms-rest-js@^2.7.0": | ||
version "2.7.0" | ||
resolved "https://registry.yarnpkg.com/@azure/ms-rest-js/-/ms-rest-js-2.7.0.tgz#8639065577ffdf4946951e1d246334ebfd72d537" | ||
integrity sha512-ngbzWbqF+NmztDOpLBVDxYM+XLcUj7nKhxGbSU9WtIsXfRB//cf2ZbAG5HkOrhU9/wd/ORRB6lM/d69RKVjiyA== | ||
dependencies: | ||
"@azure/core-auth" "^1.1.4" | ||
abort-controller "^3.0.0" | ||
form-data "^2.5.0" | ||
node-fetch "^2.6.7" | ||
tslib "^1.10.0" | ||
tunnel "0.0.6" | ||
uuid "^8.3.2" | ||
xml2js "^0.5.0" | ||
|
||
"@azure/msal-browser@^2.16.0": | ||
version "2.17.0" | ||
resolved "https://registry.yarnpkg.com/@azure/msal-browser/-/msal-browser-2.17.0.tgz#beb7d91e6123534b42c0d2ce85eda42a136a8555" | ||
|
@@ -2654,6 +2685,13 @@ abbrev@1: | |
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" | ||
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== | ||
|
||
abort-controller@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" | ||
integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== | ||
dependencies: | ||
event-target-shim "^5.0.0" | ||
|
||
accepts@^1.3.7, accepts@~1.3.8: | ||
version "1.3.8" | ||
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e" | ||
|
@@ -5857,6 +5895,11 @@ event-emitter@~0.3.5: | |
d "1" | ||
es5-ext "~0.10.14" | ||
|
||
event-target-shim@^5.0.0: | ||
version "5.0.1" | ||
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" | ||
integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== | ||
|
||
events@^3.0.0: | ||
version "3.2.0" | ||
resolved "https://registry.yarnpkg.com/events/-/events-3.2.0.tgz#93b87c18f8efcd4202a461aec4dfc0556b639379" | ||
|
@@ -13009,7 +13052,7 @@ tsconfig-paths@^3.9.0: | |
minimist "^1.2.0" | ||
strip-bom "^3.0.0" | ||
|
||
tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: | ||
tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: | ||
version "1.14.1" | ||
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00" | ||
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg== | ||
|
@@ -13046,7 +13089,7 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.1.tgz#3f05251ee17904dfd0677546670db9651682b811" | ||
integrity sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw== | ||
|
||
tunnel@^0.0.6: | ||
tunnel@0.0.6, tunnel@^0.0.6: | ||
version "0.0.6" | ||
resolved "https://registry.yarnpkg.com/tunnel/-/tunnel-0.0.6.tgz#72f1314b34a5b192db012324df2cc587ca47f92c" | ||
integrity sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg== | ||
|