Skip to content

Commit ca56a4a

Browse files
committed
Update token validation to make more sense for the new system
1 parent 5e29523 commit ca56a4a

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,3 @@ jobs:
4040
- name: Test with Gradle
4141
run: ./gradlew fg:modrinth loom:modrinth
4242
if: ${{ !contains(github.event.head_commit.message, 'skip test') }}
43-
env:
44-
MODRINTH_TOKEN: dummy_token_for_CI

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ A Gradle plugin for interfacing directly with Modrinth, through uploading build
44

55
Want to use a GitHub Action instead of a Gradle plugin? Check out [Kir-Antipov/mc-publish](https://github.com/Kir-Antipov/mc-publish), but note that Modrinth does not give support for `mc-publish` where we do for Minotaur.
66

7-
Still using Minotaur v1? You should switch as soon as possible, because it uses the deprecated API v1. Migration instructions can be found [on the Modrinth documentation page](https://docs.modrinth.com/docs/migrations/v1-to-v2/#minotaur-v1-to-v2).
8-
97
## Usage Guide
108

119
To use this plugin you must add it to your Gradle build script. After that, you can use the `modrinth` task to upload the version to Modrinth.
1210

1311
Minotaur requires a personal access token with the following scopes:
14-
- `USER_READ`
1512
- `CREATE_VERSION` (if running the `modrinth` task)
1613
- `PROJECT_WRITE` (if running the `modrinthSyncBody` task)
1714

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id 'com.gradle.plugin-publish' version '1.2.0'
33
}
44

5-
version = '2.8.3'
5+
version = '2.8.4'
66
group = 'com.modrinth.minotaur'
77
archivesBaseName = 'Minotaur'
88
description = 'Modrinth plugin for publishing builds to the website!'

src/main/java/com/modrinth/minotaur/TaskModrinthSyncBody.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
import java.util.Objects;
1111
import java.util.regex.Pattern;
1212

13-
import static com.modrinth.minotaur.Util.api;
14-
import static com.modrinth.minotaur.Util.ext;
13+
import static com.modrinth.minotaur.Util.*;
1514

1615
/**
1716
* A task used to communicate with Modrinth for the purpose of syncing project body with, for example, a README.

src/main/java/com/modrinth/minotaur/Util.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.modrinth.minotaur;
22

33
import masecla.modrinth4j.client.agent.UserAgent;
4-
import masecla.modrinth4j.exception.EndpointException;
54
import masecla.modrinth4j.main.ModrinthAPI;
6-
import masecla.modrinth4j.model.user.ModrinthUser;
75
import org.gradle.api.Project;
86
import org.gradle.api.file.RegularFile;
97
import org.gradle.api.provider.Provider;
@@ -13,7 +11,6 @@
1311
import org.jetbrains.annotations.Nullable;
1412

1513
import java.io.File;
16-
import java.util.Objects;
1714

1815
/**
1916
* Internal utility methods to make things easier and deduplicated
@@ -23,9 +20,8 @@ class Util {
2320
/**
2421
* @param project Gradle project for getting various info from
2522
* @return A valid {@link ModrinthAPI} instance
26-
* @throws EndpointException when the request to validate the token fails
2723
*/
28-
static ModrinthAPI api(Project project) throws EndpointException, NullPointerException {
24+
static ModrinthAPI api(Project project) {
2925
ModrinthExtension ext = ext(project);
3026
String url = ext.getApiUrl().get();
3127
if (url.endsWith("/")) {
@@ -39,19 +35,14 @@ static ModrinthAPI api(Project project) throws EndpointException, NullPointerExc
3935
.contact(ext.getProjectId().get() + "/" + resolveVersionNumber(project))
4036
.build();
4137

42-
String token = ext(project).getToken().get();
43-
ModrinthAPI api = ModrinthAPI.rateLimited(agent, url, token);
44-
45-
// Ensure validity of token unless in Minotaur CI
46-
if (token.equals("dummy_token_for_CI")) {
47-
project.getLogger().info("Skipping token validation (GitHub repo {})", System.getenv("GITHUB_REPOSITORY"));
48-
} else {
49-
ModrinthUser user = api.users().getSelf().join();
50-
String username = Objects.requireNonNull(user.getUsername(), "Failed to resolve username from token");
51-
project.getLogger().debug("Signed in as user {}", username);
38+
String token = ext.getToken().get();
39+
if (token.startsWith("mra")) {
40+
throw new RuntimeException("Token must be a personal-access token, not a session token!");
41+
} else if (!token.startsWith("mrp")) {
42+
project.getLogger().warn("Using GitHub tokens for authentication is deprecated. Please begin to use personal-access tokens.");
5243
}
5344

54-
return api;
45+
return ModrinthAPI.rateLimited(agent, url, token);
5546
}
5647

5748
/**

0 commit comments

Comments
 (0)