From ecc89b270900e500716b3bb8403e39f912a64f07 Mon Sep 17 00:00:00 2001 From: Henry-Hiles Date: Mon, 20 Jul 2026 11:42:36 -0400 Subject: [PATCH] pass device id scope --- lib/controllers/auth_url.dart | 3 ++- lib/models/requests/oauth/get_auth_url.dart | 26 ++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/controllers/auth_url.dart b/lib/controllers/auth_url.dart index 46f4844..1fe0695 100644 --- a/lib/controllers/auth_url.dart +++ b/lib/controllers/auth_url.dart @@ -2,6 +2,7 @@ import "package:flutter_riverpod/flutter_riverpod.dart"; import "package:nexus/controllers/client.dart"; import "package:nexus/controllers/client_id.dart"; import "package:nexus/models/oauth_auth_code_response.dart"; +import "package:nexus/models/requests/oauth/get_auth_url.dart"; class AuthUrlController extends AsyncNotifier { final Uri homeserver; @@ -15,7 +16,7 @@ class AuthUrlController extends AsyncNotifier { homeserverUrl: homeserver, redirectUri: .new(scheme: "nexus.federated.nexus", path: "/"), responseMode: .query, - scopes: .new([.clientApi]), + scopes: .new([Scope.clientApi, Scope.device]), clientId: await ref.watch( ClientIdController.provider(homeserver).future, ), diff --git a/lib/models/requests/oauth/get_auth_url.dart b/lib/models/requests/oauth/get_auth_url.dart index 68e025a..5ca5b6f 100644 --- a/lib/models/requests/oauth/get_auth_url.dart +++ b/lib/models/requests/oauth/get_auth_url.dart @@ -1,3 +1,5 @@ +import "dart:math"; + import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:freezed_annotation/freezed_annotation.dart"; part "get_auth_url.freezed.dart"; @@ -9,7 +11,7 @@ abstract class OAuthGetAuthUrl with _$OAuthGetAuthUrl { required ResponseMode responseMode, required Uri homeserverUrl, required Uri redirectUri, - required IList scopes, + required IList scopes, required String clientId, String? userIdHint, }) = _OAuthGetAuthUrl; @@ -18,11 +20,23 @@ abstract class OAuthGetAuthUrl with _$OAuthGetAuthUrl { _$OAuthGetAuthUrlFromJson(json); } -enum Scope { - openid, - email, - @JsonValue("urn:matrix:client:api:*") - clientApi, +abstract class Scope { + static final openid = "openid"; + static final email = "email"; + static final clientApi = "urn:matrix:client:api:*"; + + static final _deviceChars = IList( + ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789" + "-._~") + .split(""), + ); + + static String get _deviceId => + _deviceChars.shuffle(Random.secure()).sublist(0, 10).join(); + + static String get device => "urn:matrix:client:device:$_deviceId"; } @JsonEnum(fieldRename: .snake)