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.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,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue