Skip to content

Commit 9b7414d

Browse files
fix(auth): headers for authentication are now set
Merge pull request #4 from janetechinc/francesco/auth-headers
2 parents a81aacb + 7fdd27c commit 9b7414d

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

examples/javascript/src/lib/api-service.mjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ const defaultHost = "https://api.iheartjane.com"
77
const authenticateClient = async () => {
88
const clientId = process.env.JANE_CLIENT_ID || ''
99
const clientSecret = process.env.JANE_CLIENT_SECRET || ''
10-
const apiUrl = process.env.JANE_API_URL
10+
const apiUrl = process.env.JANE_API_URL || defaultHost
1111

1212
const resp = await request({
1313
method: 'post',
1414
url: `${apiUrl}/oauth/token`,
15-
grant_type: 'client_credentials'
16-
}, {
15+
data: {
16+
grant_type: 'client_credentials',
17+
},
1718
auth: {
1819
username: clientId,
1920
password: clientSecret
@@ -24,7 +25,7 @@ const authenticateClient = async () => {
2425
}
2526

2627
const makeRequest = async (options) => {
27-
const apiUrl = process.env.JANE_API_URL
28+
const apiUrl = process.env.JANE_API_URL || defaultHost
2829

2930
if (!apiUrl) {
3031
throw Error('No JANE_API_URL configured')

examples/javascript/src/lib/api-service.spec.mjs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ describe('api service', () => {
1616
)
1717
})
1818

19-
describe('if no JANE_API_URL is set', () => {
20-
test('it throws an error', async () => {
21-
const token = 'someToken'
22-
23-
await expect(async () => {
24-
await apiService.post('/api/path', {}, token)
25-
}).rejects.toEqual(new Error('No JANE_API_URL configured'))
26-
})
27-
})
28-
2919
describe('#get', () => {
3020
beforeEach(() => {
3121
process.env.JANE_API_URL = 'https://test.localhost'

0 commit comments

Comments
 (0)