Mher Arsh
Mher Arsh

Reputation: 597

ServiceStack OAuth2 mobile native authentication

I need to log on through OAuth 2 how can I do that without using WebView in Android? Thanks.

Upvotes: 1

Views: 68

Answers (1)

mythz
mythz

Reputation: 143284

In the latest v4.5.7 of ServiceStack you'll be able to login into Twitter, Facebook or Github using their SDKs and previous saved access tokens.

Authentication via AccessToken is also made available to OAuth2 providers in the same way where you can authenticate directly by adding the AccessToken to the Authenticate Request DTO, e.g:

var request = new Authenticate
{
    provider = "GoogleOAuth",
    AccessToken = GoogleOAuthAccessToken,
};

var response = client.Post(request);
response.PrintDump();

Although you will first need to retrieve the AccessToken which typically requires opening a WebView to capture Users consent.

For other OAuth2 providers other than Google Auth you will need to provide an implementation of VerifyAccessToken that returns a boolean that determines whether the AccessToken is valid or not, e.g:

new MyOAuth2Provider {
    VerifyAccessToken = accessToken => MyValidate(ConsumerKey,accessToken),
}

This is different for each OAuth provider where some don't provide an API that lets you determine whether the AccessToken is valid with your App or not.

Upvotes: 2

Related Questions