Flutter google sign in with SS Auth

Hi,
I’m trying to get my head around the best way to reuse my SS login web page, that has a Google sign in option for a Flutter application, is this possible? Or would I have to implement dart code to login into a google account to get a JWT and then pass onto my SS services?

Thanks

The Google AuthProvider supports authenticating via an AccessToken which is what you’d use when authenticating from a native Mobile or Desktop App where their Sign In widget results in getting an AccessToken which you’d then use to Authenticate with ServiceStack.

The AndroidJavaChat Android App shows an example of Signing in using their Google widget although the new dependency-free GoogleAuthProvider uses the google AuthProvider name:

App.get().getServiceClient().postAsync(new dtos.Authenticate()
    .setProvider("google")
    .setAccessToken(accessToken)
    .setRememberMe(true),
    r -> {
        UiHelpers.setStatus(txtStatus, "Server google sign-in successful");
        stopProgressBar();
        startActivity(new Intent(activity, MainActivity.class));
    },
    error -> {
        UiHelpers.setStatusError(txtStatus, "Server google sign-in failed", error);
        stopProgressBar();
    });

The Sign In with Apple project shows a similar integration but with the new Sign In with Apple Auth Provider which contains a Flutter App showing how to sign in with both Android & iOS:

Although Android support is a bit different as it’s just a wrapper around a custom web view where as it’s able to use the native support in iOS. But it’s essentially the same approach where the widget is responsible for obtaining the AccessToken after a successful Sign In which you would use to authenticate with ServiceStack which either returns an Authenticated Session on the client or if you use the new JWT UseTokenCookie support you can optionally configure for authenticating via an OAuth Provider to return the session in a stateless JWT Token which your native Mobile/Desktop App would persist instead.

Here’s what Authenticating via an AccessToken, saving the Authenticated Response + restoring the JWT Cookies in the persisted AuthenticateResponse to create an Authenticated ServiceClient should look like all together:

// Authenticate with server using idToken & convert into stateless JWT Cookie
var response = await client.post(Authenticate()
    ..provider = 'google'
    ..accessToken = accessToken); 

// Example of persisting AuthenticateResponse in Flutter's Shared Preferences
prefs = await SharedPreferences.getInstance();
var json = jsonEncode(response.toJson());
prefs.setString('auth', json);

//...

//Restoring saved JWT to create Authenticated ServiceClient without resigning in
client.bearerToken = auth?.bearerToken;
client.refreshToken = auth?.refreshToken;

var json = prefs.getString('auth');
var auth = json != null ? AuthenticateResponse.fromJson(jsonDecode(json)) : null;
client.bearerToken = auth?.bearerToken;
client.refreshToken = auth?.refreshToken;

This example assumes you’re using JWT & its UseTokenCookie support to return the authenticated session in a stateless JWT Cookie which is my recommendation when needing to support native Mobile/Desktop Apps.

Great, thanks for pointing me in the right direction