Skip to content

Commit 02b8d7e

Browse files
committed
Fix to token authentication.
1 parent 032658c commit 02b8d7e

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

lib/commands/login._js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,13 @@ exports.init = function (cli) {
6363
options.token = undefined;
6464
}
6565

66-
var supportedLoginTypeText = $('Please note that currently you can login only via username/password. ' +
66+
var supportedLoginTypeText = $('Please note that currently you can only login via username/password or username/token. ' +
6767
'To create an account, visit http://dnsimple.com.');
6868
log.warn(supportedLoginTypeText);
6969

7070
var username = cli.interaction.promptIfNotGiven('Username: ', options.user, _);
7171

7272
var token = options.token;
73-
// if (options.password === undefined) {
74-
// token = cli.interaction.promptIfNotGiven('API Token: ', options.token, _);
75-
// }
7673

7774
if (!tokenCache.isSecureCache) {
7875
var haveSeenBefore = __.values(profile.current.subscriptions).some(function (s) {

lib/util/authentication/dnsimpleAuth.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,14 @@ _.extend(ServicePrincipalAccessToken.prototype, {
258258
*/
259259
function acquireToken(authConfig, username, password, callback) {
260260
//var context = createAuthenticationContext(authConfig);
261-
var dns = new dnsimple({ email: username, password: password, hostname: authConfig.resourceId.replace('https://','') });
261+
var options = { email: username };
262+
if (authConfig.token) {
263+
options['token'] = authConfig.token;
264+
} else {
265+
options['password'] = password;
266+
}
267+
options['hostname'] = authConfig.resourceId.replace('https://','');
268+
var dns = new dnsimple(options);
262269

263270
dns.talk('GET', 'user', function(err, response) {
264271
if (err) { return callback(err); }

lib/util/profile/environment.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ _.extend(Environment.prototype, {
136136
// clientId: constants.XPLAT_CLI_CLIENT_ID
137137
authorityUrl: this.apiTokenEndpointUrl,
138138
apiVersion: this.apiVersion,
139-
//token: token,
139+
token: token,
140140
resourceId: this.apiEndpointUrl,
141141
clientId: constants.DNSIMPLE_CLI_CLIENT_ID
142142
};
@@ -174,23 +174,19 @@ _.extend(Environment.prototype, {
174174
callback(null, subs);
175175
}
176176

177-
if (!token) {
178-
subscriptionUtils.getSubscriptions(self, username, password, processSubscriptions);
179-
} else {
180-
dnsimpleAuth.acquireServicePrincipalToken(self.getAuthConfig(token), username, password, function (err, token) {
181-
if (err) { return callback(err); }
182-
subscriptionUtils.getSubscriptionsInTenant(self, username, tenant, token, processSubscriptions);
183-
});
184-
}
177+
subscriptionUtils.getSubscriptions(self, username, token, password, processSubscriptions);
185178
},
186179

187180
acquireToken : function (username, password, token, callback) {
188181
dnsimpleAuth.acquireToken(this.getAuthConfig(token), username, password, callback);
189182
},
190183

191184
getDnsimpleClient: function (credentials) {
192-
return new dnsimple({ email: credentials.userId, token: credentials.accessToken, hostname: this.apiEndpointUrl.replace('https://','') });
193-
//return resourceClient.createResourceSubscriptionClient(credentials, this.resourceManagerEndpointUrl);
185+
var options = { email: credentials.userId };
186+
options['token'] = credentials.authConfig.token || credentials.accessToken;
187+
options['hostname'] = this.apiEndpointUrl.replace('https://','');
188+
var dns = new dnsimple(options);
189+
return dns;
194190
}
195191
});
196192

lib/util/profile/subscriptionUtils._js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ var util = require('util');
2323
var AccessTokenCloudCredentials = require('../authentication/accessTokenCloudCredentials');
2424
var utils = require('../utils');
2525

26-
function getSubscriptions(environment, username, password, _) {
27-
var accessToken = environment.acquireToken(username, password, '', _);
26+
function getSubscriptions(environment, username, token, password, _) {
27+
var accessToken = environment.acquireToken(username, password, token, _);
2828
username = crossCheckUserNameWithToken(username, accessToken.userId);
2929
//var dns = environment.getDnsimpleClient(createCredential(accessToken));
3030
var dns = environment.getDnsimpleClient(accessToken);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"contributors": [
55
"Anderly, Adam <[email protected]>"
66
],
7-
"version": "0.3.0",
7+
"version": "0.3.1",
88
"description": "DNSimple Command Line tool",
99
"tags": [
1010
"dnsimple",

0 commit comments

Comments
 (0)