OAuth Support #53
2 changed files with 22 additions and 7 deletions
pass device id scope
commit
ecc89b2709
|
|
@ -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<OAuthAuthCodeResponse> {
|
||||
final Uri homeserver;
|
||||
|
|
@ -15,7 +16,7 @@ class AuthUrlController extends AsyncNotifier<OAuthAuthCodeResponse> {
|
|||
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,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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<Scope> scopes,
|
||||
required IList<String> 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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue