-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from @azure/core-http to @azure/core-rest-pipeline (#1040)
- Loading branch information
1 parent
2f626c2
commit 358fbce
Showing
9 changed files
with
500 additions
and
608 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 |
---|---|---|
@@ -1,34 +1,34 @@ | ||
import http = require("http"); | ||
import https = require("https"); | ||
import azureCore = require("@azure/core-http"); | ||
import azureCoreAuth = require("@azure/core-auth"); | ||
import azureCore = require("@azure/core-rest-pipeline"); | ||
|
||
const applicationInsightsResource = "https://monitor.azure.com//.default"; | ||
|
||
|
||
function emptySendRequest(_request: azureCore.PipelineRequest): Promise<azureCore.PipelineResponse> { | ||
return null; | ||
} | ||
|
||
class AuthorizationHandler { | ||
|
||
private _azureTokenPolicy: azureCore.RequestPolicy; | ||
private _azureTokenPolicy: azureCore.PipelinePolicy; | ||
|
||
constructor(credential: azureCore.TokenCredential) { | ||
constructor(credential: azureCoreAuth.TokenCredential) { | ||
let scopes: string[] = [applicationInsightsResource]; | ||
let emptyPolicy: azureCore.RequestPolicy = { | ||
sendRequest(httpRequest: azureCore.WebResourceLike): Promise<azureCore.HttpOperationResponse> { | ||
return null; | ||
} | ||
}; | ||
this._azureTokenPolicy = azureCore.bearerTokenAuthenticationPolicy(credential, scopes).create(emptyPolicy, new azureCore.RequestPolicyOptions()); | ||
this._azureTokenPolicy = azureCore.bearerTokenAuthenticationPolicy({credential, scopes}); | ||
} | ||
|
||
/** | ||
* Applies the Bearer token to the request through the Authorization header. | ||
*/ | ||
public async addAuthorizationHeader(requestOptions: http.RequestOptions | https.RequestOptions): Promise<void> { | ||
let authHeaderName = azureCore.Constants.HeaderConstants.AUTHORIZATION; | ||
let webResource = new azureCore.WebResource("https://"); | ||
await this._azureTokenPolicy.sendRequest(webResource); | ||
let authHeaderName = "authorization"; | ||
let webResource = azureCore.createPipelineRequest({ url: "https://" }); | ||
await this._azureTokenPolicy.sendRequest(webResource, emptySendRequest); | ||
console.log("#### webResource", webResource); | ||
requestOptions.headers[authHeaderName] = webResource.headers.get(authHeaderName); | ||
} | ||
|
||
} | ||
|
||
export = AuthorizationHandler; | ||
export = AuthorizationHandler; |
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
Oops, something went wrong.