Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/celest_cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- name: Setup Flutter
uses: subosito/flutter-action@e938fdf56512cc96ef2f93601a5a40bde3801046 # 2.19.0
with:
channel: beta
cache: true
- name: Get Packages
working-directory: packages/celest_cloud
Expand All @@ -32,4 +33,4 @@ jobs:
run: dart analyze --fatal-infos --fatal-warnings .
- name: Format
working-directory: packages/celest_cloud
run: dart format --set-exit-if-changed .
run: dart format --language-version=latest --set-exit-if-changed .
5 changes: 5 additions & 0 deletions packages/celest_cloud/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# NEXT

- chore: Re-format with Dart 3.8
- chore: Update linter/style preferences

# 0.1.8

- feat: Add `ProjectAsset_Type.DART_EXECUTABLE`
Expand Down
164 changes: 66 additions & 98 deletions packages/celest_cloud/lib/src/cloud/authentication/authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ final class Authentication with BaseService {
required AuthenticationProtocol protocol,
ClientType clientType = ClientType.CLIENT_TYPE_UNSPECIFIED,
this.logger,
}) : _clientType = clientType,
_protocol = protocol;
}) : _clientType = clientType,
_protocol = protocol;

final AuthenticationProtocol _protocol;
@override
Expand Down Expand Up @@ -40,7 +40,7 @@ final class Authentication with BaseService {
sessionId: state?.sessionId,
sessionToken: state?.sessionToken,
);
final response = await run(
final EndSessionResponse response = await run(
'Authentication.EndSession',
request: request,
action: _protocol.endSession,
Expand All @@ -61,18 +61,12 @@ final class EmailAuthentication with BaseService {
final Logger? logger;
final ClientType _clientType;

Future<EmailSessionState> start({
required String email,
}) async {
Future<EmailSessionState> start({required String email}) async {
final request = StartSessionRequest(
emailOtp: AuthenticationFactorEmailOtp(
email: email,
),
client: SessionClient(
clientType: _clientType,
),
emailOtp: AuthenticationFactorEmailOtp(email: email),
client: SessionClient(clientType: _clientType),
);
final response = await run(
final Session response = await run(
'Email.StartSession',
request: request,
action: _client.startSession,
Expand Down Expand Up @@ -108,12 +102,10 @@ final class EmailAuthentication with BaseService {
sessionId: state.sessionId,
sessionToken: state.sessionToken,
resend: AuthenticationFactor(
emailOtp: AuthenticationFactorEmailOtp(
email: state.email,
),
emailOtp: AuthenticationFactorEmailOtp(email: state.email),
),
);
final response = await run(
final Session response = await run(
'Email.ContinueSession',
request: request,
action: _client.continueSession,
Expand All @@ -139,13 +131,10 @@ final class EmailAuthentication with BaseService {
sessionId: state.sessionId,
sessionToken: state.sessionToken,
proof: AuthenticationFactor(
emailOtp: AuthenticationFactorEmailOtp(
email: state.email,
code: code,
),
emailOtp: AuthenticationFactorEmailOtp(email: state.email, code: code),
),
);
final response = await run(
final Session response = await run(
'Email.ContinueSession',
request: request,
action: _client.continueSession,
Expand All @@ -170,35 +159,33 @@ final class EmailAuthentication with BaseService {
sessionId: state.sessionId,
sessionToken: state.sessionToken,
confirmation: switch (state) {
EmailSessionRegisterUser(:final user) =>
AuthenticationPendingConfirmation(
registerUser: user,
),
EmailSessionRegisterUser(:final User user) =>
AuthenticationPendingConfirmation(registerUser: user),
},
);
final response = await run(
final Session response = await run(
'Email.ContinueSession',
request: request,
action: _client.continueSession,
);
return switch (response.whichState()) {
Session_State.nextStep when response.nextStep.hasNeedsProof() => switch (
response.nextStep.needsProof.whichFactor()) {
Session_State.nextStep when response.nextStep.hasNeedsProof() =>
switch (response.nextStep.needsProof.whichFactor()) {
AuthenticationFactor_Factor.emailOtp => EmailSessionVerifyCode(
sessionId: response.sessionId,
sessionToken: response.sessionToken,
email: state.email,
),
sessionId: response.sessionId,
sessionToken: response.sessionToken,
email: state.email,
),
_ => throw StateError('Unexpected response: $response'),
},
Session_State.success => EmailSessionSuccess(
sessionId: response.sessionId,
sessionToken: response.sessionToken,
identityToken: response.success.identityToken,
user: response.success.user,
isNewUser: response.success.isNewUser,
email: state.email,
),
sessionId: response.sessionId,
sessionToken: response.sessionToken,
identityToken: response.success.identityToken,
user: response.success.user,
isNewUser: response.success.isNewUser,
email: state.email,
),
_ => throw StateError('Unexpected response: $response'),
};
}
Expand All @@ -212,18 +199,12 @@ final class SmsAuthentication with BaseService {
final Logger? logger;
final ClientType _clientType;

Future<SmsSessionState> start({
required String phoneNumber,
}) async {
Future<SmsSessionState> start({required String phoneNumber}) async {
final request = StartSessionRequest(
smsOtp: AuthenticationFactorSmsOtp(
phoneNumber: phoneNumber,
),
client: SessionClient(
clientType: _clientType,
),
smsOtp: AuthenticationFactorSmsOtp(phoneNumber: phoneNumber),
client: SessionClient(clientType: _clientType),
);
final response = await run(
final Session response = await run(
'Sms.StartSession',
request: request,
action: _client.startSession,
Expand Down Expand Up @@ -259,12 +240,10 @@ final class SmsAuthentication with BaseService {
sessionId: state.sessionId,
sessionToken: state.sessionToken,
resend: AuthenticationFactor(
smsOtp: AuthenticationFactorSmsOtp(
phoneNumber: state.phoneNumber,
),
smsOtp: AuthenticationFactorSmsOtp(phoneNumber: state.phoneNumber),
),
);
final response = await run(
final Session response = await run(
'Sms.ContinueSession',
request: request,
action: _client.continueSession,
Expand Down Expand Up @@ -296,7 +275,7 @@ final class SmsAuthentication with BaseService {
),
),
);
final response = await run(
final Session response = await run(
'Sms.ContinueSession',
request: request,
action: _client.continueSession,
Expand All @@ -321,35 +300,33 @@ final class SmsAuthentication with BaseService {
sessionId: state.sessionId,
sessionToken: state.sessionToken,
confirmation: switch (state) {
SmsSessionRegisterUser(:final user) =>
AuthenticationPendingConfirmation(
registerUser: user,
),
SmsSessionRegisterUser(:final User user) =>
AuthenticationPendingConfirmation(registerUser: user),
},
);
final response = await run(
final Session response = await run(
'Sms.ContinueSession',
request: request,
action: _client.continueSession,
);
return switch (response.whichState()) {
Session_State.nextStep when response.nextStep.hasNeedsProof() => switch (
response.nextStep.needsProof.whichFactor()) {
Session_State.nextStep when response.nextStep.hasNeedsProof() =>
switch (response.nextStep.needsProof.whichFactor()) {
AuthenticationFactor_Factor.smsOtp => SmsSessionVerifyCode(
sessionId: response.sessionId,
sessionToken: response.sessionToken,
phoneNumber: state.phoneNumber,
),
sessionId: response.sessionId,
sessionToken: response.sessionToken,
phoneNumber: state.phoneNumber,
),
_ => throw StateError('Unexpected response: $response'),
},
Session_State.success => SmsSessionSuccess(
sessionId: response.sessionId,
sessionToken: response.sessionToken,
identityToken: response.success.identityToken,
user: response.success.user,
isNewUser: response.success.isNewUser,
phoneNumber: state.phoneNumber,
),
sessionId: response.sessionId,
sessionToken: response.sessionToken,
identityToken: response.success.identityToken,
user: response.success.user,
isNewUser: response.success.isNewUser,
phoneNumber: state.phoneNumber,
),
_ => throw StateError('Unexpected response: $response'),
};
}
Expand All @@ -368,17 +345,13 @@ final class IdpAuthentication with BaseService {
required Uri redirectUri,
}) async {
final request = StartSessionRequest(
idp: AuthenticationFactorIdp(
provider: provider,
),
idp: AuthenticationFactorIdp(provider: provider),
client: SessionClient(
clientType: _clientType,
callbacks: SessionCallbacks(
successUri: redirectUri.toString(),
),
callbacks: SessionCallbacks(successUri: redirectUri.toString()),
),
);
final response = await run(
final Session response = await run(
'Idp.StartSession',
request: request,
action: _client.startSession,
Expand All @@ -391,9 +364,7 @@ final class IdpAuthentication with BaseService {
sessionId: response.sessionId,
sessionToken: response.sessionToken,
provder: provider,
uri: Uri.parse(
response.nextStep.needsProof.idp.redirectUri,
),
uri: Uri.parse(response.nextStep.needsProof.idp.redirectUri),
),
_ => throw StateError('Unexpected response: $response'),
};
Expand All @@ -413,7 +384,7 @@ final class IdpAuthentication with BaseService {
),
),
);
final response = await run(
final Session response = await run(
'Idp.ContinueSession',
request: request,
action: _client.continueSession,
Expand All @@ -436,12 +407,12 @@ final class IdpAuthentication with BaseService {
_ => throw StateError('Unexpected response: $response'),
},
Session_State.success => IdpSessionSuccess(
sessionId: response.sessionId,
sessionToken: response.sessionToken,
identityToken: response.success.identityToken,
user: response.success.user,
isNewUser: response.success.isNewUser,
),
sessionId: response.sessionId,
sessionToken: response.sessionToken,
identityToken: response.success.identityToken,
user: response.success.user,
isNewUser: response.success.isNewUser,
),
_ => throw StateError('Unexpected response: $response'),
};
}
Expand All @@ -453,16 +424,13 @@ final class IdpAuthentication with BaseService {
sessionId: state.sessionId,
sessionToken: state.sessionToken,
confirmation: switch (state) {
IdpSessionLinkUser(:final user) => AuthenticationPendingConfirmation(
linkExistingUser: user,
),
IdpSessionRegisterUser(:final user) =>
AuthenticationPendingConfirmation(
registerUser: user,
),
IdpSessionLinkUser(:final User user) =>
AuthenticationPendingConfirmation(linkExistingUser: user),
IdpSessionRegisterUser(:final User user) =>
AuthenticationPendingConfirmation(registerUser: user),
},
);
final response = await run(
final Session response = await run(
'Idp.ContinueSession',
request: request,
action: _client.continueSession,
Expand Down
Loading