* feat: update runtime to node 24 * fix: deps * feat: update create token endpoint (#311) /v2/users/login was deprecated in favor of using /v2/auth/token to create access tokens. Switching endpoints adds support for creating auth tokens from OATs. * fix: use correct response property * feat: switch to native fetch * fix: method name --------- Co-authored-by: Ian Pittwood <pittwoodian@gmail.com>
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as fetch from 'node-fetch'
|
||||
|
||||
export async function getToken(
|
||||
username: string,
|
||||
password: string
|
||||
): Promise<string> {
|
||||
const body = {
|
||||
username: username,
|
||||
password: password
|
||||
identifier: username,
|
||||
secret: password
|
||||
}
|
||||
const response = await fetch('https://hub.docker.com/v2/users/login', {
|
||||
method: 'post',
|
||||
const response = await fetch('https://hub.docker.com/v2/auth/token', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
headers: {'Content-Type': 'application/json'}
|
||||
})
|
||||
@@ -20,8 +19,8 @@ export async function getToken(
|
||||
)
|
||||
}
|
||||
const json = await response.json()
|
||||
core.setSecret(json['token'])
|
||||
return json['token']
|
||||
core.setSecret(json['access_token'])
|
||||
return json['access_token']
|
||||
}
|
||||
|
||||
export async function updateRepositoryDescription(
|
||||
@@ -37,11 +36,11 @@ export async function updateRepositoryDescription(
|
||||
body['description'] = description
|
||||
}
|
||||
await fetch(`https://hub.docker.com/v2/repositories/${repository}`, {
|
||||
method: 'patch',
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `JWT ${token}`
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}).then(res => {
|
||||
if (!res.ok) {
|
||||
|
||||
Reference in New Issue
Block a user