function authenticationBeforeRequest (state, options) { if (!state.auth.type) { return } if (state.auth.type === 'basic') { const hash = btoa(`${state.auth.username}:${state.auth.password}`) options.headers['authorization'] = `Basic ${hash}` return } if (state.auth.type === 'token') { options.headers['authorization'] = `token ${state.auth.token}` return } if (state.auth.type === 'app') { options.headers['authorization'] = `Bearer ${state.auth.token}` const acceptHeaders = options.headers['accept'].split(',') .concat('application/vnd.github.machine-man-preview+json') options.headers['accept'] = uniq(acceptHeaders).filter(Boolean).join(',') return } options.url += options.url.indexOf('?') === -1 ? '?' : '&' if (state.auth.token) { options.url += `access_token=${encodeURIComponent(state.auth.token)}` return } const key = encodeURIComponent(state.auth.key) const secret = encodeURIComponent(state.auth.secret) options.url += `client_id=${key}&client_secret=${secret}` }
it('octokit.repos.createFile()', () => { return octokit.repos.createFile({ owner: 'octokit-fixture-org', repo: 'create-file', path: 'test.txt', message: 'create test.txt', content: btoa('Test content') }) .then((response) => { expect(response.data.content.type).to.equal('file') }) })
it('options.auth=basic without prefix', () => { nock('https://authentication-test-host.com', { reqheaders: { authorization: 'basic Zm9vLWJhcjpzZWNyZXQ=' } }) .get('/') .reply(200, {}) const octokit = new Octokit({ baseUrl: 'https://authentication-test-host.com', auth: btoa('foo-bar:secret') }) return octokit.request('/') })
auth: () => btoa('foo-bar:secret')