Skip to content

Commit

Permalink
Delete TokenCredentials, update samples to use RawTokenCredential
Browse files Browse the repository at this point in the history
  • Loading branch information
daviwil committed Jul 23, 2019
1 parent f80f304 commit f8f1304
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 106 deletions.
12 changes: 6 additions & 6 deletions sdk/core/core-arm/samples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

<head>
<title>My Todos</title>
<script type="text/javascript" src="../node_modules/ms-rest-ts/msRestBundle.js"></script>
<script type="text/javascript" src="../msRestAzureBundle.js"></script>
<script type="text/javascript" src="../node_modules/@azure/core-http/dist/coreHttp.browser.js"></script>
<script type="text/javascript" src="../dist/coreArm.js"></script>

<script type="text/javascript">
document.write("hello world");
const subscriptionId = "subscriptionId";
const token = "token";
const creds = new msRest.TokenCredentials(token);
const client = new msRestAzure.AzureServiceClient(creds);
const creds = new Azure.Core.HTTP.RawTokenCredential(token);
const client = new Azure.Core.ARM.AzureServiceClient(creds);
const req = {
url: `https://management.azure.com/subscriptions/${subscriptionId}/providers/Microsoft.Storage/storageAccounts?api-version=2015-06-15`,
method: "GET"
Expand All @@ -23,4 +23,4 @@
<body>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion sdk/core/core-arm/samples/node-sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const apiVersion = "2017-06-01";
// 1.5 in the curl tab you will see the actual curl request that has the bearer token in it
// 1.6 copy paste that token here. That token is valid for 1 hour
const token = "token";
const creds = new coreHttp.TokenCredentials(token);
const creds = new coreHttp.RawTokenCredential(token);
const client = new coreArm.AzureServiceClient(creds, clientOptions);
const req: coreHttp.RequestPrepareOptions = {
url: `https://management.azure.com/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Storage/storageAccounts/${accountName}?api-version=${apiVersion}`,
Expand Down
1 change: 0 additions & 1 deletion sdk/core/core-http/lib/coreHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export { URLBuilder, URLQuery } from "./url";
// Credentials
export { TokenCredential, GetTokenOptions, AccessToken, isTokenCredential, RawTokenCredential } from "@azure/core-auth";
export { AccessTokenCache, ExpiringAccessTokenCache } from "./credentials/accessTokenCache";
export { TokenCredentials } from "./credentials/tokenCredentials";
export { BasicAuthenticationCredentials } from "./credentials/basicAuthenticationCredentials";
export { ApiKeyCredentials, ApiKeyCredentialOptions } from "./credentials/apiKeyCredentials";
export { ServiceClientCredentials } from "./credentials/serviceClientCredentials";
Expand Down
45 changes: 0 additions & 45 deletions sdk/core/core-http/lib/credentials/tokenCredentials.ts

This file was deleted.

9 changes: 4 additions & 5 deletions sdk/core/core-http/samples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

<head>
<title>My Todos</title>
<script type="text/javascript" src="../msRestBundle.js"></script>
<script type="text/javascript" src="../dist/coreHttp.browser.js"></script>
<script type="text/javascript">
document.write('hello world');
const msRest = className;
const subscriptionId = "00977cdb-163f-435f-9c32-39ec8ae61f4d";
const token = "token";
const creds = new msRest.TokenCredentials(token);
const client = new msRest.ServiceClient(creds);
const creds = new Azure.Core.HTTP.RawTokenCredential(token);
const client = new Azure.Core.HTTP.ServiceClient(creds);
const req = {
url: `https://management.azure.com/subscriptions/${subscriptionId}/providers/Microsoft.Storage/storageAccounts?api-version=2015-06-15`,
method: "GET"
Expand All @@ -22,4 +21,4 @@
<body>
</body>

</html>
</html>
48 changes: 0 additions & 48 deletions sdk/core/core-http/test/credentialTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,12 @@
import "chai/register-should";
import * as msRest from "../lib/coreHttp";
import * as base64 from "../lib/util/base64";
const TokenCredentials = msRest.TokenCredentials;
const BasicAuthenticationCredentials = msRest.BasicAuthenticationCredentials;
const ApiKeyCredentials = msRest.ApiKeyCredentials;
const dummyToken = "A-dummy-access-token";
const fakeScheme = "fake-auth-scheme";
const dummyUsername = "dummy@mummy.com";
const dummyPassword = "IL0veDummies";

describe("Token credentials", () => {
describe("usage", () => {
it("should set auth header with bearer scheme in request", (done) => {
const creds = new TokenCredentials(dummyToken);
const request = new msRest.WebResource();

creds.signRequest(request).then((signedRequest: msRest.WebResource) => {
signedRequest.headers.get("authorization")!.should.exist;
signedRequest.headers.get("authorization")!.should.match(new RegExp("^Bearer\\s+" + dummyToken + "$"));
done();
});
});

it("should set auth header with custom scheme in request", (done) => {
const creds = new TokenCredentials(dummyToken, fakeScheme);
const request = new msRest.WebResource();
creds.signRequest(request).then((signedRequest: msRest.WebResource) => {
signedRequest.headers.get("authorization")!.should.exist;
signedRequest.headers.get("authorization")!.should.match(new RegExp("^" + fakeScheme + "\\s+" + dummyToken + "$"));
done();
});
});
});

describe("construction", () => {

it("should succeed with token", () => {
(() => {
new TokenCredentials(dummyToken);
}).should.not.throw();
});

// it("should fail without credentials", () => {
// (() => {
// new TokenCredentials();
// }).should.throw();
// });

// it("should fail without token", () => {
// (() => {
// new TokenCredentials(null, fakeScheme);
// }).should.throw();
// });
});
});

describe("Basic Authentication credentials", () => {
const encodedCredentials = base64.encodeString(dummyUsername + ":" + dummyPassword);
describe("usage", () => {
Expand Down

0 comments on commit f8f1304

Please sign in to comment.