Compare commits
No commits in common. "cac64864c6135b415c76c6fe9a91dc2592f5a2fa" and "ce267a4c66aab357fe8f55622612213f9f69d39b" have entirely different histories.
cac64864c6
...
ce267a4c66
4 changed files with 6 additions and 128 deletions
17
build.gradle
17
build.gradle
|
@ -30,13 +30,6 @@ loom {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
|
||||||
include {
|
|
||||||
canBeResolved = true
|
|
||||||
canBeConsumed = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// To change the versions see the gradle.properties file
|
// To change the versions see the gradle.properties file
|
||||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
|
@ -46,12 +39,6 @@ dependencies {
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
// OAuth2 library
|
|
||||||
implementation 'com.google.oauth-client:google-oauth-client:1.39.0'
|
|
||||||
|
|
||||||
// Configuration library
|
|
||||||
include 'com.electronwill.night-config:toml:3.6.0'
|
|
||||||
implementation 'com.electronwill.night-config:toml:3.6.0'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
@ -82,10 +69,6 @@ jar {
|
||||||
from("LICENSE") {
|
from("LICENSE") {
|
||||||
rename { "${it}_${inputs.properties.archivesName}"}
|
rename { "${it}_${inputs.properties.archivesName}"}
|
||||||
}
|
}
|
||||||
|
|
||||||
from {
|
|
||||||
configurations.include.collect { it.isDirectory() ? it : zipTree(it) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure the maven publication
|
// configure the maven publication
|
||||||
|
|
|
@ -19,9 +19,6 @@ public class OAuthFabric implements ModInitializer {
|
||||||
// However, some things (like resources) may still be uninitialized.
|
// However, some things (like resources) may still be uninitialized.
|
||||||
// Proceed with mild caution.
|
// Proceed with mild caution.
|
||||||
|
|
||||||
OAuthFabricConfig oAuthFabricConfig = new OAuthFabricConfig();
|
LOGGER.info("Hello Fabric world!");
|
||||||
oAuthFabricConfig.load();
|
|
||||||
|
|
||||||
LOGGER.info("oauth-fabric: Initialized");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,102 +0,0 @@
|
||||||
package dev.lilyvex.oauthfabric;
|
|
||||||
|
|
||||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
|
||||||
import com.electronwill.nightconfig.core.io.ParsingException;
|
|
||||||
import com.electronwill.nightconfig.core.io.ParsingMode;
|
|
||||||
import com.electronwill.nightconfig.toml.TomlParser;
|
|
||||||
import com.electronwill.nightconfig.toml.TomlWriter;
|
|
||||||
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.NoSuchFileException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class OAuthFabricConfig {
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger("oauth-fabric");
|
|
||||||
private static final String DEFAULT_PROVIDER = "auth.lilyvex.dev";
|
|
||||||
private static final String DEFAULT_CLIENT_ID = "minecraft";
|
|
||||||
private static final String DEFAULT_CLIENT_SECRET = "<No default secret>";
|
|
||||||
private static final String DEFAULT_REDIRECT_URI = "mc.lilyvex.dev/oauth2";
|
|
||||||
private static final String DEFAULT_DATABASE = "sqlite";
|
|
||||||
|
|
||||||
public static final Path CONFIG_FILE_PATH = FabricLoader.getInstance().getConfigDir()
|
|
||||||
.resolve("oauth-fabric.toml")
|
|
||||||
.normalize();
|
|
||||||
|
|
||||||
private final CommentedConfig config = CommentedConfig.inMemory();
|
|
||||||
|
|
||||||
// URL to the OAuth provider (e.g. accounts.google.com, discord.com/oauth2)
|
|
||||||
private String provider;
|
|
||||||
|
|
||||||
// ID of the OAuth client. This is usually defined when creating the OAuth application.
|
|
||||||
private String client_id;
|
|
||||||
|
|
||||||
// Client secret
|
|
||||||
private String client_secret;
|
|
||||||
|
|
||||||
// URI to redirect to. Ensure that this URI is listed in the allowed redirect URIs section
|
|
||||||
// of your OAuth provider.
|
|
||||||
private String redirect_uri;
|
|
||||||
|
|
||||||
// Which database to use (SQLite is currently the only supported database).
|
|
||||||
private String database;
|
|
||||||
|
|
||||||
public void load() {
|
|
||||||
this.config.getOrElse("provider", DEFAULT_PROVIDER);
|
|
||||||
this.config.getOrElse("client_id", DEFAULT_CLIENT_ID);
|
|
||||||
this.config.getOrElse("client_secret", DEFAULT_CLIENT_SECRET);
|
|
||||||
this.config.getOrElse("redirect_uri", DEFAULT_REDIRECT_URI);
|
|
||||||
this.config.getOrElse("database", DEFAULT_DATABASE);
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.loadFromFile(true);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGGER.info("oauth-fabric: Configuration loaded.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadFromFile(boolean firstAttempt) throws IOException {
|
|
||||||
try (var reader = Files.newBufferedReader(CONFIG_FILE_PATH)) {
|
|
||||||
new TomlParser().parse(reader, this.config, ParsingMode.REPLACE);
|
|
||||||
} catch (NoSuchFileException | FileNotFoundException e) {
|
|
||||||
if (!firstAttempt) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.copyDefaultFile();
|
|
||||||
this.loadFromFile(true);
|
|
||||||
} catch (ParsingException e) {
|
|
||||||
if (!firstAttempt) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
var backupPath = CONFIG_FILE_PATH.resolveSibling("oauth-fabric.toml.old").toAbsolutePath().normalize();
|
|
||||||
|
|
||||||
LOGGER.error("oauth-fabric: Failed to parse configuration file, THIS IS BAD.", e);
|
|
||||||
LOGGER.error("oauth-fabric: Copying the corrupt file to \"{}\".", backupPath);
|
|
||||||
Files.copy(CONFIG_FILE_PATH, backupPath, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
this.copyDefaultFile();
|
|
||||||
this.loadFromFile(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyDefaultFile() throws IOException {
|
|
||||||
Files.createDirectories(CONFIG_FILE_PATH.getParent());
|
|
||||||
|
|
||||||
try (var writer = Files.newBufferedWriter(CONFIG_FILE_PATH, StandardCharsets.UTF_8)) {
|
|
||||||
new TomlWriter().write(this.config.unmodifiable(), writer);
|
|
||||||
} catch (NoSuchFileException | FileNotFoundException e) {
|
|
||||||
LOGGER.error("oauth-fabric: Failed to write default configuration file.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,15 +3,15 @@
|
||||||
"id": "oauth-fabric",
|
"id": "oauth-fabric",
|
||||||
"version": "${version}",
|
"version": "${version}",
|
||||||
"name": "OAuth Fabric",
|
"name": "OAuth Fabric",
|
||||||
"description": "OAuth2 authentication for Fabric Minecraft servers",
|
"description": "This is an example description! Tell everyone what your mod is about!",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Lily Vex"
|
"Me!"
|
||||||
],
|
],
|
||||||
"contact": {
|
"contact": {
|
||||||
"homepage": "https://code.lilyvex.dev/lily/oauth-fabric",
|
"homepage": "https://fabricmc.net/",
|
||||||
"sources": "https://code.lilyvex.dev/lily/oauth-fabric"
|
"sources": "https://github.com/FabricMC/fabric-example-mod"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "CC0-1.0",
|
||||||
"icon": "assets/oauth-fabric/icon.png",
|
"icon": "assets/oauth-fabric/icon.png",
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue