1+ using System . Text . Json . Serialization ;
12using FwLiteShared . Projects ;
3+ using Microsoft . Extensions . Logging ;
24using Microsoft . Extensions . Options ;
35using Microsoft . JSInterop ;
46
57namespace FwLiteShared . Auth ;
68
79public record ServerStatus ( string DisplayName , bool LoggedIn , string ? LoggedInAs , LexboxServer Server ) ;
8- public class AuthService ( LexboxProjectService lexboxProjectService , OAuthClientFactory clientFactory , IOptions < AuthConfig > options )
10+
11+ [ JsonConverter ( typeof ( JsonStringEnumConverter ) ) ]
12+ public enum LoginResult
13+ {
14+ Success ,
15+ Offline ,
16+ Cancelled ,
17+ }
18+
19+ public class AuthService (
20+ LexboxProjectService lexboxProjectService ,
21+ OAuthClientFactory clientFactory ,
22+ ILogger < AuthService > logger ,
23+ IOptions < AuthConfig > options )
924{
1025 [ JSInvokable ]
1126 public async Task < ServerStatus [ ] > Servers ( )
@@ -21,11 +36,22 @@ public async Task<ServerStatus[]> Servers()
2136 }
2237
2338 [ JSInvokable ]
24- public async Task SignInWebView ( LexboxServer server )
39+ public async Task < LoginResult > SignInWebView ( LexboxServer server )
2540 {
26- var result = await clientFactory . GetClient ( server ) . SignIn ( string . Empty ) ; //does nothing here
27- if ( ! result . HandledBySystemWebView ) throw new InvalidOperationException ( "Sign in not handled by system web view" ) ;
28- options . Value . AfterLoginWebView ? . Invoke ( ) ;
41+ try
42+ {
43+ var result = await clientFactory . GetClient ( server ) . SignIn ( string . Empty ) ; //does nothing here
44+ if ( ! result . HandledBySystemWebView ) throw new InvalidOperationException ( "Sign in not handled by system web view" ) ;
45+ options . Value . AfterLoginWebView ? . Invoke ( ) ;
46+ return LoginResult . Success ;
47+ }
48+ catch ( Exception e )
49+ {
50+ var classified = OAuthClient . ClassifyInteractiveLoginFailure ( e ) ;
51+ if ( classified is null ) throw ;
52+ logger . LogInformation ( e , "Web view sign in did not complete: {LoginResult}" , classified ) ;
53+ return classified . Value ;
54+ }
2955 }
3056
3157 [ JSInvokable ]
0 commit comments