Skip to content

Commit d49f1c4

Browse files
committed
feat: login with subdomain
1 parent 5eaf7b5 commit d49f1c4

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/Api.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,21 @@ export class Api {
102102
* @memberOf Api
103103
* @param {String} username A username in Workfront
104104
* @param {String} password Password to use
105+
* @param {String} subdomain Sub-domain to use
105106
* @return {Promise} A promise which will resolved with API key if everything went ok and rejected otherwise
106107
*/
107-
getApiKey(username: string, password: string): Promise<string> {
108+
getApiKey(username: string, password: string, subdomain: string): Promise<string> {
108109
return new Promise((resolve, reject) => {
109110
if (typeof this._httpOptions.headers.apiKey !== 'undefined') {
110111
resolve(this._httpOptions.headers.apiKey)
111112
} else {
112-
const req = this.execute('USER', null, 'getApiKey', {username, password})
113+
const req = this.execute('USER', null, 'getApiKey', {username, password, subdomain})
113114
;(req as Promise<any>).then(getApiKeyData => {
114115
if (getApiKeyData.result === '') {
115116
const req2 = this.execute('USER', null, 'generateApiKey', {
116117
username,
117-
password
118+
password,
119+
subdomain
118120
})
119121
;(req2 as Promise<any>).then(generateApiKeyData => {
120122
this._httpOptions.headers.apiKey = generateApiKeyData.result
@@ -292,12 +294,13 @@ export class Api {
292294
* @memberOf Api
293295
* @param {String} username A username in Workfront
294296
* @param {String} password Password to use
297+
* @param {String} subdomain Sub-domain to use
295298
* @return {Promise} A promise which will resolved with logged in user data if everything went ok and rejected otherwise
296299
*/
297-
login(username: string, password: string) {
300+
login(username: string, password: string, subdomain: string) {
298301
const req = this.request(
299302
'login',
300-
{username: username, password: password},
303+
{username: username, password: password, subdomain: subdomain},
301304
null,
302305
Api.Methods.POST
303306
)

src/main.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/node.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ export class NodeApi extends BaseApi {
4646
}
4747

4848
export {ResponseHandler} from './Api'
49+
50+
export {NodeApi as Api}

test/e2e.test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ describe('E2E Tests', function() {
1010
const rootTestTitle = this.title
1111
let customerID, resellerID, accountRepID
1212
let USERNAME = 'new@user.attask',
13-
PASSWORD = 'user'
13+
PASSWORD = 'user',
14+
SUBDOMAIN = 'attask'
1415

1516
before('Create Test Customer', function() {
1617
this.aspInstance = new Workfront.Api({
@@ -54,7 +55,8 @@ describe('E2E Tests', function() {
5455
onDemandOptions: 'PWDDISAB', // PASSWORD_COMPLEXITY_DISABLE
5556
securityModelType: 'D', // Lucid
5657
status: 'A', // ACTIVE
57-
timeZone: 'UTC'
58+
timeZone: 'UTC',
59+
domain: SUBDOMAIN
5860
})
5961
.then(data => {
6062
customerID = data.ID
@@ -118,7 +120,7 @@ describe('E2E Tests', function() {
118120
describe('Login with username and password', function() {
119121
beforeEach(function() {
120122
return this.instance
121-
.login(USERNAME, PASSWORD)
123+
.login(USERNAME, PASSWORD, SUBDOMAIN)
122124
.then(data => {
123125
should(data).have.properties('userID', 'sessionID')
124126
should.ok(true, 'user logged in')
@@ -486,7 +488,7 @@ describe('E2E Tests', function() {
486488

487489
describe('With no auto-login in beforeEach', function() {
488490
it("Gets apiKey for the User, gets user's details, clear the apiKey", function() {
489-
return this.instance.getApiKey(USERNAME, PASSWORD).then(data => {
491+
return this.instance.getApiKey(USERNAME, PASSWORD, SUBDOMAIN).then(data => {
490492
should(data)
491493
.be.String()
492494
.length(32)
@@ -506,7 +508,7 @@ describe('E2E Tests', function() {
506508
version: '7.0',
507509
alwaysUseGet: true
508510
})
509-
return instance.login(USERNAME, PASSWORD).then(() =>
511+
return instance.login(USERNAME, PASSWORD, SUBDOMAIN).then(() =>
510512
instance
511513
.create('PROJ', {
512514
name: 'API Project',
@@ -520,7 +522,7 @@ describe('E2E Tests', function() {
520522
})
521523

522524
it('Creates a group "Api Group", edits the name to read "Api Group 2", then deletes it -- Chained', function() {
523-
const login = () => this.instance.login(USERNAME, PASSWORD)
525+
const login = () => this.instance.login(USERNAME, PASSWORD, SUBDOMAIN)
524526
const createGroup = () => this.instance.create('group', {name: 'Api Group'})
525527
const editGroup = data =>
526528
this.instance.edit('group', data.ID, {name: 'Api Group 2'}, ['ID'])
@@ -533,7 +535,7 @@ describe('E2E Tests', function() {
533535
})
534536

535537
it('Logs in and logs out', function() {
536-
return this.instance.login(USERNAME, PASSWORD).then(data => {
538+
return this.instance.login(USERNAME, PASSWORD, SUBDOMAIN).then(data => {
537539
should(data).have.properties('userID', 'sessionID')
538540
return this.instance.logout()
539541
})

0 commit comments

Comments
 (0)