fix: clearer errors for custom server addresses
This commit is contained in:
1 parent
da8048a2d4
commit
e2c72bcff8
2 files changed
+73
-36
No files matched your search
@@ -29,11 +29,11 @@ session in the refresh token column as JSON behind a marker.
|
||||
apps/app/src/api/auth.rs | 49 +++
|
||||
packages/app-lib/src/api/minecraft_auth.rs | 47 +-
|
||||
packages/app-lib/src/state/minecraft_auth.rs | 402 +++++++++++++++++-
|
||||
packages/app-lib/src/util/authlib_injector.rs | 94 ++++
|
||||
7 files changed, 782 insertions(+), 14 deletions(-)
|
||||
packages/app-lib/src/util/authlib_injector.rs | 100 +++++
|
||||
7 files changed, 788 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/apps/app-frontend/src/components/ui/AuthlibAccountModal.vue b/apps/app-frontend/src/components/ui/AuthlibAccountModal.vue
|
||||
index 4aab3f9..b67b2c7 100644
|
||||
index a2873fe..0e1f9a7 100644
|
||||
--- a/apps/app-frontend/src/components/ui/AuthlibAccountModal.vue
|
||||
+++ b/apps/app-frontend/src/components/ui/AuthlibAccountModal.vue
|
||||
@@ -1,5 +1,11 @@
|
||||
@@ -49,7 +49,7 @@ index 4aab3f9..b67b2c7 100644
|
||||
<div class="flex flex-col gap-4">
|
||||
<p class="m-0 leading-tight text-secondary">
|
||||
{{ formatMessage(messages.description) }}
|
||||
@@ -40,6 +46,52 @@
|
||||
@@ -47,6 +53,52 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -102,7 +102,7 @@ index 4aab3f9..b67b2c7 100644
|
||||
<div class="flex flex-col gap-2">
|
||||
<label class="font-semibold text-contrast" for="authlib-account-username">
|
||||
{{ formatMessage(messages.usernameLabel) }}
|
||||
@@ -126,6 +178,8 @@
|
||||
@@ -133,6 +185,8 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
CheckIcon,
|
||||
@@ -111,7 +111,7 @@ index 4aab3f9..b67b2c7 100644
|
||||
GlobeIcon,
|
||||
KeyIcon,
|
||||
LogInIcon,
|
||||
@@ -138,13 +192,20 @@ import {
|
||||
@@ -145,13 +199,20 @@ import {
|
||||
Chips,
|
||||
commonMessages,
|
||||
defineMessages,
|
||||
@@ -133,7 +133,7 @@ index 4aab3f9..b67b2c7 100644
|
||||
|
||||
type Server = {
|
||||
api_root: string
|
||||
@@ -152,8 +213,16 @@ type Server = {
|
||||
@@ -159,8 +220,16 @@ type Server = {
|
||||
implementation?: string
|
||||
homepage?: string
|
||||
register?: string
|
||||
@@ -150,10 +150,10 @@ index 4aab3f9..b67b2c7 100644
|
||||
|
||||
const { formatMessage } = useVIntl()
|
||||
|
||||
@@ -171,7 +240,15 @@ const profiles = ref<Profile[]>([])
|
||||
const profile = ref<Profile | null>(null)
|
||||
@@ -179,7 +248,15 @@ const profile = ref<Profile | null>(null)
|
||||
const error = ref('')
|
||||
const submitting = ref(false)
|
||||
const lookingUp = ref(false)
|
||||
+const browser = ref<DeviceCode | null>(null)
|
||||
+const browserStarting = ref(false)
|
||||
+const browserError = ref('')
|
||||
@@ -165,9 +165,9 @@ index 4aab3f9..b67b2c7 100644
|
||||
+let pollTimeout: ReturnType<typeof setTimeout> | undefined
|
||||
|
||||
function message(e: unknown) {
|
||||
return typeof e === 'string' ? e : ((e as Error)?.message ?? formatMessage(messages.genericError))
|
||||
@@ -187,6 +264,8 @@ watch(address, () => {
|
||||
lookup++
|
||||
const text =
|
||||
@@ -199,6 +276,8 @@ watch(address, () => {
|
||||
lookingUp.value = false
|
||||
server.value = null
|
||||
serverError.value = ''
|
||||
+ stopBrowser()
|
||||
@@ -175,7 +175,7 @@ index 4aab3f9..b67b2c7 100644
|
||||
})
|
||||
|
||||
function show(event?: MouseEvent) {
|
||||
@@ -199,6 +278,8 @@ function show(event?: MouseEvent) {
|
||||
@@ -211,6 +290,8 @@ function show(event?: MouseEvent) {
|
||||
profile.value = null
|
||||
error.value = ''
|
||||
submitting.value = false
|
||||
@@ -184,7 +184,7 @@ index 4aab3f9..b67b2c7 100644
|
||||
modal.value?.show(event)
|
||||
void nextTick(() => {
|
||||
document.getElementById('authlib-account-server')?.focus()
|
||||
@@ -219,6 +300,72 @@ async function lookUpServer() {
|
||||
@@ -235,6 +316,72 @@ async function lookUpServer() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ index 4aab3f9..b67b2c7 100644
|
||||
async function submit() {
|
||||
if (submitting.value) return
|
||||
|
||||
@@ -282,6 +429,34 @@ const messages = defineMessages({
|
||||
@@ -309,6 +456,34 @@ const messages = defineMessages({
|
||||
id: 'app.authlib-account.password-label',
|
||||
defaultMessage: 'Password',
|
||||
},
|
||||
@@ -935,10 +935,10 @@ index b916a6d..e9fa853 100644
|
||||
return Ok(());
|
||||
}
|
||||
diff --git a/packages/app-lib/src/util/authlib_injector.rs b/packages/app-lib/src/util/authlib_injector.rs
|
||||
index 709e6d0..8788563 100644
|
||||
index 13591ef..487b0ae 100644
|
||||
--- a/packages/app-lib/src/util/authlib_injector.rs
|
||||
+++ b/packages/app-lib/src/util/authlib_injector.rs
|
||||
@@ -17,6 +17,90 @@ use crate::state::DirectoryInfo;
|
||||
@@ -17,6 +17,96 @@ use crate::state::DirectoryInfo;
|
||||
use crate::util::fetch::{INSECURE_REQWEST_CLIENT, REQWEST_CLIENT};
|
||||
use crate::util::io;
|
||||
|
||||
@@ -951,8 +951,11 @@ index 709e6d0..8788563 100644
|
||||
+const CONNECT_CLIENT_IDS: &[(&str, &str)] = &[];
|
||||
+
|
||||
+/// The scopes a Yggdrasil Connect sign-in for playing needs.
|
||||
+const CONNECT_SCOPES: [&str; 3] =
|
||||
+ ["openid", "Yggdrasil.PlayerProfiles.Select", "Yggdrasil.Server.Join"];
|
||||
+const CONNECT_SCOPES: [&str; 3] = [
|
||||
+ "openid",
|
||||
+ "Yggdrasil.PlayerProfiles.Select",
|
||||
+ "Yggdrasil.Server.Join",
|
||||
+];
|
||||
+
|
||||
+/// How to sign in to a server with Yggdrasil Connect, OAuth's device flow on
|
||||
+/// the server's own page.
|
||||
@@ -998,7 +1001,10 @@ index 709e6d0..8788563 100644
|
||||
+ .iter()
|
||||
+ .all(|endpoint| endpoint.starts_with("https://"));
|
||||
+ let supported = |scope: &str| {
|
||||
+ config.scopes_supported.iter().any(|supported| supported == scope)
|
||||
+ config
|
||||
+ .scopes_supported
|
||||
+ .iter()
|
||||
+ .any(|supported| supported == scope)
|
||||
+ };
|
||||
+ if !https || !CONNECT_SCOPES.iter().all(|scope| supported(scope)) {
|
||||
+ return None;
|
||||
@@ -1029,7 +1035,7 @@ index 709e6d0..8788563 100644
|
||||
/// An authlib-injector server, as its own metadata describes it.
|
||||
#[derive(Serialize, Debug, Clone)]
|
||||
pub struct AuthlibServer {
|
||||
@@ -27,6 +111,8 @@ pub struct AuthlibServer {
|
||||
@@ -27,6 +117,8 @@ pub struct AuthlibServer {
|
||||
pub implementation: Option<String>,
|
||||
pub homepage: Option<String>,
|
||||
pub register: Option<String>,
|
||||
@@ -1038,7 +1044,7 @@ index 709e6d0..8788563 100644
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -46,6 +132,8 @@ struct Meta {
|
||||
@@ -46,6 +138,8 @@ struct Meta {
|
||||
implementation_name: Option<String>,
|
||||
#[serde(default)]
|
||||
links: Links,
|
||||
@@ -1047,7 +1053,7 @@ index 709e6d0..8788563 100644
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
@@ -115,6 +203,11 @@ pub async fn resolve_server(address: &str) -> crate::Result<AuthlibServer> {
|
||||
@@ -119,6 +213,11 @@ pub async fn resolve_server(address: &str) -> crate::Result<AuthlibServer> {
|
||||
))
|
||||
})?;
|
||||
|
||||
@@ -1059,7 +1065,7 @@ index 709e6d0..8788563 100644
|
||||
Ok(AuthlibServer {
|
||||
api_root: api_root.as_str().trim_end_matches('/').to_owned(),
|
||||
name: metadata
|
||||
@@ -125,6 +218,7 @@ pub async fn resolve_server(address: &str) -> crate::Result<AuthlibServer> {
|
||||
@@ -129,6 +228,7 @@ pub async fn resolve_server(address: &str) -> crate::Result<AuthlibServer> {
|
||||
implementation: metadata.meta.implementation_name,
|
||||
homepage: metadata.meta.links.homepage,
|
||||
register: metadata.meta.links.register,
|
||||
|
||||
Reference in new issue
Block a user