@@ -71,6 +71,21 @@ static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthentic
71
71
tcsResponse = new TaskCompletionSource < WebAuthenticatorResult > ( ) ;
72
72
currentRedirectUri = callbackUrl ;
73
73
74
+ if ( ! ( await StartCustomTabsActivity ( url ) ) )
75
+ {
76
+ // Fall back to opening the system-registered browser if necessary
77
+ var urlOriginalString = url . OriginalString ;
78
+ var browserIntent = new Intent ( Intent . ActionView , global ::Android . Net . Uri . Parse ( urlOriginalString ) ) ;
79
+ Platform . CurrentActivity . StartActivity ( browserIntent ) ;
80
+ }
81
+
82
+ return await tcsResponse . Task ;
83
+ }
84
+
85
+ static async Task < bool > StartCustomTabsActivity ( Uri url )
86
+ {
87
+ // Is only set to true if BindServiceAsync succeeds and no exceptions are thrown
88
+ var success = false ;
74
89
var parentActivity = Platform . GetCurrentActivity ( true ) ;
75
90
76
91
var customTabsActivityManager = CustomTabsActivityManager . From ( parentActivity ) ;
@@ -84,16 +99,12 @@ static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthentic
84
99
85
100
customTabsIntent . Intent . SetData ( global ::Android . Net . Uri . Parse ( url . OriginalString ) ) ;
86
101
87
- WebAuthenticatorIntermediateActivity . StartActivity ( parentActivity , customTabsIntent . Intent ) ;
88
- }
89
- else
90
- {
91
- // Fall back to opening the system browser if necessary
92
- var browserIntent = new Intent ( Intent . ActionView , global ::Android . Net . Uri . Parse ( url . OriginalString ) ) ;
93
- Platform . CurrentActivity . StartActivity ( browserIntent ) ;
102
+ if ( customTabsIntent . Intent . ResolveActivity ( parentActivity . PackageManager ) != null )
103
+ {
104
+ WebAuthenticatorIntermediateActivity . StartActivity ( parentActivity , customTabsIntent . Intent ) ;
105
+ success = true ;
106
+ }
94
107
}
95
-
96
- return await tcsResponse . Task ;
97
108
}
98
109
finally
99
110
{
@@ -105,6 +116,8 @@ static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(WebAuthentic
105
116
{
106
117
}
107
118
}
119
+
120
+ return success ;
108
121
}
109
122
110
123
static Task < bool > BindServiceAsync ( CustomTabsActivityManager manager )
0 commit comments