Skip to content

Commit eda77fa

Browse files
authored
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.
1 parent db95ca9 commit eda77fa

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

dist/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ const fetch = __importStar(__nccwpck_require__(6705));
4545
function getToken(username, password) {
4646
return __awaiter(this, void 0, void 0, function* () {
4747
const body = {
48-
username: username,
49-
password: password
48+
identifier: username,
49+
secret: password
5050
};
51-
const response = yield fetch('https://hub.docker.com/v2/users/login', {
51+
const response = yield fetch('https://hub.docker.com/v2/auth/token', {
5252
method: 'post',
5353
body: JSON.stringify(body),
5454
headers: { 'Content-Type': 'application/json' }
@@ -75,7 +75,7 @@ function updateRepositoryDescription(token, repository, description, fullDescrip
7575
body: JSON.stringify(body),
7676
headers: {
7777
'Content-Type': 'application/json',
78-
Authorization: `JWT ${token}`
78+
Authorization: `Bearer ${token}`
7979
}
8080
}).then(res => {
8181
if (!res.ok) {

src/dockerhub-helper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export async function getToken(
66
password: string
77
): Promise<string> {
88
const body = {
9-
username: username,
10-
password: password
9+
identifier: username,
10+
secret: password
1111
}
12-
const response = await fetch('https://hub.docker.com/v2/users/login', {
12+
const response = await fetch('https://hub.docker.com/v2/auth/token', {
1313
method: 'post',
1414
body: JSON.stringify(body),
1515
headers: {'Content-Type': 'application/json'}
@@ -41,7 +41,7 @@ export async function updateRepositoryDescription(
4141
body: JSON.stringify(body),
4242
headers: {
4343
'Content-Type': 'application/json',
44-
Authorization: `JWT ${token}`
44+
Authorization: `Bearer ${token}`
4545
}
4646
}).then(res => {
4747
if (!res.ok) {

0 commit comments

Comments
 (0)