mobile bluesky app made with flutter
lazurite.stormlightlabs.org/
mobile
bluesky
flutter
1import 'package:equatable/equatable.dart';
2
3enum AuthMethod { appPassword, oauth }
4
5class AuthTokens extends Equatable {
6 const AuthTokens({
7 required this.accessToken,
8 this.refreshToken,
9 this.expiresAt,
10 required this.did,
11 required this.handle,
12 this.displayName,
13 this.service,
14 this.oauthService,
15 this.dpopNonce,
16 this.dpopPublicKey,
17 this.dpopPrivateKey,
18 this.authMethod = AuthMethod.appPassword,
19 });
20 final String accessToken;
21 final String? refreshToken;
22 final DateTime? expiresAt;
23 final String did;
24 final String handle;
25 final String? displayName;
26 final String? service;
27 final String? oauthService;
28 final String? dpopNonce;
29 final String? dpopPublicKey;
30 final String? dpopPrivateKey;
31 final AuthMethod authMethod;
32
33 AuthTokens copyWith({
34 String? accessToken,
35 String? refreshToken,
36 DateTime? expiresAt,
37 String? did,
38 String? handle,
39 String? displayName,
40 String? service,
41 String? oauthService,
42 String? dpopNonce,
43 String? dpopPublicKey,
44 String? dpopPrivateKey,
45 AuthMethod? authMethod,
46 }) {
47 return AuthTokens(
48 accessToken: accessToken ?? this.accessToken,
49 refreshToken: refreshToken ?? this.refreshToken,
50 expiresAt: expiresAt ?? this.expiresAt,
51 did: did ?? this.did,
52 handle: handle ?? this.handle,
53 displayName: displayName ?? this.displayName,
54 service: service ?? this.service,
55 oauthService: oauthService ?? this.oauthService,
56 dpopNonce: dpopNonce ?? this.dpopNonce,
57 dpopPublicKey: dpopPublicKey ?? this.dpopPublicKey,
58 dpopPrivateKey: dpopPrivateKey ?? this.dpopPrivateKey,
59 authMethod: authMethod ?? this.authMethod,
60 );
61 }
62
63 bool get usesOAuth => authMethod == AuthMethod.oauth;
64
65 bool get isExpired {
66 if (expiresAt == null) return false;
67 return DateTime.now().isAfter(expiresAt!.subtract(const Duration(minutes: 5)));
68 }
69
70 @override
71 List<Object?> get props => [
72 accessToken,
73 refreshToken,
74 expiresAt,
75 did,
76 handle,
77 displayName,
78 service,
79 oauthService,
80 dpopNonce,
81 dpopPublicKey,
82 dpopPrivateKey,
83 authMethod,
84 ];
85}
86
87class User extends Equatable {
88 const User({required this.did, required this.handle, this.displayName, this.avatar, this.description});
89 final String did;
90 final String handle;
91 final String? displayName;
92 final String? avatar;
93 final String? description;
94
95 User copyWith({String? did, String? handle, String? displayName, String? avatar, String? description}) {
96 return User(
97 did: did ?? this.did,
98 handle: handle ?? this.handle,
99 displayName: displayName ?? this.displayName,
100 avatar: avatar ?? this.avatar,
101 description: description ?? this.description,
102 );
103 }
104
105 @override
106 List<Object?> get props => [did, handle, displayName, avatar, description];
107}