Skip to content

Commit

Permalink
fix: Resolve path to keys (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay-google committed Jan 8, 2024
1 parent bac6f83 commit c6c2fc6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as opn from 'open';
import arrify = require('arrify');
import destroyer = require('server-destroy');
import {AddressInfo} from 'net';
import {resolve} from 'path';

const invalidRedirectUri = `The provided keyfile does not define a valid
redirect URI. There must be at least one redirect URI defined, and this sample
Expand Down Expand Up @@ -59,7 +60,7 @@ export async function authenticate(
}

// eslint-disable-next-line @typescript-eslint/no-var-requires
const keyFile = require(options.keyfilePath);
const keyFile = require(resolve(options.keyfilePath));
const keys = keyFile.installed || keyFile.web;
if (!keys.redirect_uris || keys.redirect_uris.length === 0) {
throw new Error(invalidRedirectUri);
Expand Down
20 changes: 20 additions & 0 deletions test/test.index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,24 @@ describe('🔑 authenticate', () => {
/Cannot read/
);
});

it('should return credentials for a relative keyfilePath', async () => {
const access_token = 'fake-access-token';
const refresh_token = 'fake-refresh-token';
const scope = nock('https://oauth2.googleapis.com')
.post('/token')
.reply(200, {
access_token,
refresh_token,
});
const keyfilePath = 'test/fixtures/keys.json';

const client = await nla.authenticate({
keyfilePath: keyfilePath,
scopes: [],
});
scope.done();
assert.strictEqual(client.credentials.access_token, access_token);
assert.strictEqual(client.credentials.refresh_token, refresh_token);
});
});

0 comments on commit c6c2fc6

Please sign in to comment.