Skip to content

Commit

Permalink
fix: set a proper user-agent string
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Mar 16, 2022
1 parent 877fb1f commit 1fbb173
Show file tree
Hide file tree
Showing 14 changed files with 9 additions and 27 deletions.
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const NAME = 'oauth4webapi'
const VERSION = 'v0.0.1' // TODO: bump during standard-version prerelease
const HOMEPAGE = 'https://github.com/panva/oauth4webapi'
const USER_AGENT = `${NAME}/${VERSION} (${HOMEPAGE})`

/**
* Interface to pass an asymmetric public key and, optionally, its associated
* JWK Key ID to be added as a `kid` JOSE Header Parameter.
Expand Down Expand Up @@ -775,7 +780,7 @@ export async function discoveryRequest(
}

return fetch(url.href, {
headers: new Headers({ accept: 'application/json', 'user-agent': 'uatbd' }),
headers: new Headers({ accept: 'application/json', 'user-agent': USER_AGENT }),
method: 'GET',
redirect: 'manual',
signal: options?.signal,
Expand Down Expand Up @@ -1656,7 +1661,7 @@ export async function protectedResourceRequest(
headers.set('authorization', `DPoP ${accessToken}`)
}

headers.set('user-agent', 'uatbd')
headers.set('user-agent', USER_AGENT)

return fetch(url.href, {
body,
Expand Down Expand Up @@ -2021,7 +2026,7 @@ async function authenticatedRequest(
headers: Headers,
options?: SignalledRequestOptions & AuthenticatedRequestOptions,
) {
headers.set('user-agent', 'uatbd')
headers.set('user-agent', USER_AGENT)

await clientAuthentication(as, client, body, headers, options?.clientPrivateKey)

Expand Down Expand Up @@ -3072,7 +3077,7 @@ export async function jwksRequest(
const headers = new Headers()
headers.set('accept', 'application/json')
headers.append('accept', 'application/jwk-set+json')
headers.set('user-agent', 'uatbd')
headers.set('user-agent', USER_AGENT)

return fetch(url.href, {
headers,
Expand Down
1 change: 0 additions & 1 deletion test/authorization_code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ test('authorizationCodeGrantRequest()', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
body(body) {
const params = new URLSearchParams(body)
Expand Down
4 changes: 0 additions & 4 deletions test/client_auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ test('client_secret_basic', async (t) => {
path: '/test-basic',
method: 'POST',
headers: {
'user-agent': 'uatbd',
authorization: (header) => header.startsWith('Basic '),
},
body(body) {
Expand Down Expand Up @@ -155,9 +154,6 @@ test('none', async (t) => {
.intercept({
path: '/test-none',
method: 'POST',
headers: {
'user-agent': 'uatbd',
},
body(body) {
const params = new URLSearchParams(body)
return params.has('client_id') && !params.has('client_secret')
Expand Down
1 change: 0 additions & 1 deletion test/client_credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ test('clientCredentialsGrantRequest()', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
body(body) {
const params = new URLSearchParams(body)
Expand Down
2 changes: 0 additions & 2 deletions test/device_flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ test('deviceAuthorizationRequest()', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
body(body) {
return new URLSearchParams(body).get('client_id') === client.client_id
Expand Down Expand Up @@ -209,7 +208,6 @@ test('deviceCodeGrantRequest()', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
body(body) {
const params = new URLSearchParams(body)
Expand Down
1 change: 0 additions & 1 deletion test/discovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ test('discoveryRequest()', async (t) => {
method: 'GET',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
})
.reply(200, data)
Expand Down
1 change: 0 additions & 1 deletion test/dpop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test('dpop()', async (t) => {
t.is(ath, crypto.createHash('sha256').update('token').digest('base64url'))
return true
},
'user-agent': 'uatbd',
},
})
.reply(200, '')
Expand Down
4 changes: 0 additions & 4 deletions test/introspection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ test('introspectionRequest()', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
body(body) {
return new URLSearchParams(body).get('token') === 'token'
Expand Down Expand Up @@ -94,7 +93,6 @@ test('introspectionRequest() forced jwt', async (t) => {
method: 'POST',
headers: {
accept: 'application/token-introspection+jwt',
'user-agent': 'uatbd',
},
body(body) {
return new URLSearchParams(body).get('token') === 'token'
Expand All @@ -119,7 +117,6 @@ test('introspectionRequest() jwt through client metadata', async (t) => {
method: 'POST',
headers: {
accept: 'application/token-introspection+jwt',
'user-agent': 'uatbd',
},
body(body) {
return new URLSearchParams(body).get('token') === 'token'
Expand Down Expand Up @@ -148,7 +145,6 @@ test('introspectionRequest() forced json', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
body(body) {
return new URLSearchParams(body).get('token') === 'token'
Expand Down
1 change: 0 additions & 1 deletion test/jwks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ test('jwksRequest()', async (t) => {
method: 'GET',
headers: {
accept: 'application/json, application/jwk-set+json',
'user-agent': 'uatbd',
},
})
.reply(200, data)
Expand Down
3 changes: 0 additions & 3 deletions test/par.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test('pushedAuthorizationRequest()', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
body(body) {
return new URLSearchParams(body).get('client_id') === client.client_id
Expand All @@ -54,7 +53,6 @@ test('pushedAuthorizationRequest() w/ DPoP', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
dpop: /.+/,
},
body(body) {
Expand All @@ -81,7 +79,6 @@ test('pushedAuthorizationRequest() w/ Request Object', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
body(body) {
const params = new URLSearchParams(body)
Expand Down
1 change: 0 additions & 1 deletion test/protected_resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ test('protectedResource()', async (t) => {
method: 'GET',
headers: {
authorization: 'Bearer token',
'user-agent': 'uatbd',
},
})
.reply(200, '')
Expand Down
1 change: 0 additions & 1 deletion test/refresh_token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ test('refreshTokenGrantRequest()', async (t) => {
method: 'POST',
headers: {
accept: 'application/json',
'user-agent': 'uatbd',
},
body(body) {
const params = new URLSearchParams(body)
Expand Down
1 change: 0 additions & 1 deletion test/revocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ test('revocationRequest()', async (t) => {
method: 'POST',
headers: {
accept: '*/*',
'user-agent': 'uatbd',
},
body(body) {
return new URLSearchParams(body).get('token') === 'token'
Expand Down
2 changes: 0 additions & 2 deletions test/userinfo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ test('userInfoRequest()', async (t) => {
method: 'GET',
headers: {
accept: 'application/json, application/jwt',
'user-agent': 'uatbd',
},
})
.reply(200, data)
Expand All @@ -53,7 +52,6 @@ test('userInfoRequest() w/ jwt signal', async (t) => {
method: 'GET',
headers: {
accept: 'application/jwt',
'user-agent': 'uatbd',
},
})
.reply(200, data)
Expand Down

0 comments on commit 1fbb173

Please sign in to comment.