OAuth Support #53

Merged
Henry-Hiles merged 17 commits from quad/feat/oauth-login into main 2026-07-20 19:46:19 -04:00
2 changed files with 22 additions and 7 deletions
Showing only changes of commit ecc89b2709 - Show all commits

pass device id scope

Henry Hiles 2026-07-20 11:42:36 -04:00
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -2,6 +2,7 @@ import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:nexus/controllers/client.dart"; import "package:nexus/controllers/client.dart";
import "package:nexus/controllers/client_id.dart"; import "package:nexus/controllers/client_id.dart";
import "package:nexus/models/oauth_auth_code_response.dart"; import "package:nexus/models/oauth_auth_code_response.dart";
import "package:nexus/models/requests/oauth/get_auth_url.dart";
class AuthUrlController extends AsyncNotifier<OAuthAuthCodeResponse> { class AuthUrlController extends AsyncNotifier<OAuthAuthCodeResponse> {
final Uri homeserver; final Uri homeserver;
@ -15,7 +16,7 @@ class AuthUrlController extends AsyncNotifier<OAuthAuthCodeResponse> {
homeserverUrl: homeserver, homeserverUrl: homeserver,
redirectUri: .new(scheme: "nexus.federated.nexus", path: "/"), redirectUri: .new(scheme: "nexus.federated.nexus", path: "/"),
responseMode: .query, responseMode: .query,
scopes: .new([.clientApi]), scopes: .new([Scope.clientApi, Scope.device]),
clientId: await ref.watch( clientId: await ref.watch(
ClientIdController.provider(homeserver).future, ClientIdController.provider(homeserver).future,
), ),

View file

@ -1,3 +1,5 @@
import "dart:math";
import "package:fast_immutable_collections/fast_immutable_collections.dart"; import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart"; import "package:freezed_annotation/freezed_annotation.dart";
part "get_auth_url.freezed.dart"; part "get_auth_url.freezed.dart";
@ -9,7 +11,7 @@ abstract class OAuthGetAuthUrl with _$OAuthGetAuthUrl {
required ResponseMode responseMode, required ResponseMode responseMode,
required Uri homeserverUrl, required Uri homeserverUrl,
required Uri redirectUri, required Uri redirectUri,
required IList<Scope> scopes, required IList<String> scopes,
required String clientId, required String clientId,
String? userIdHint, String? userIdHint,
}) = _OAuthGetAuthUrl; }) = _OAuthGetAuthUrl;
@ -18,11 +20,23 @@ abstract class OAuthGetAuthUrl with _$OAuthGetAuthUrl {
_$OAuthGetAuthUrlFromJson(json); _$OAuthGetAuthUrlFromJson(json);
} }
enum Scope { abstract class Scope {
openid, static final openid = "openid";
email, static final email = "email";
@JsonValue("urn:matrix:client:api:*") static final clientApi = "urn:matrix:client:api:*";
clientApi,
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) @JsonEnum(fieldRename: .snake)