Package com.stytch.sdk.b2b.oauth
The OAuth.kt interface provides methods for authenticating a user via a any of the following third-party OAuth providers, provided you have configured them within your Stytch Dashboard:
Google
Microsoft
In order to use provider OAuth flows, there are a few settings you need to configure in your application.
First, ensure you have added the relevant manifest placeholders in your application's build.gradle file (as explained in the /README.md).
Second, you must specify a unique identifier for the activity result:
const val STYTCH_B2B_OAUTH_REQUEST = 456Third, in your activity, add a listener for that unique identifier in onActivityResult, like so:
class MyActivity : AppCompatActivity() {
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
STYTCH_B2B_OAUTH_REQUEST -> data?.let { viewModel.authenticateB2BOAuth(resultCode, it) }
}
}
}To begin a Provider OAuth flow, call wither the StytchB2BClient.oauth.[PROVIDER].start() or StytchB2BClient.oauth.[PROVIDER].discovery.start() methods, ensuring you pass in the unique OAuth identifier defined previously. This will spawn a new (manager) activity that opens the user's default browser to begin the authentication flow. When the authentication flow has concluded, a new receiver activity intercepts the result, and returns it to the manager activity, which ultimately returns a response to your activity. This helps keep the backstack in order.
Once you have retrieved the data from the returned intent, you can pass the required parameters to the StytchB2BClient.oauth.authenticate() or StytchB2BClient.oauth.discovery.authenticate() method, as appropriate, to complete the authentication flow.
See: Description
-
Class Summary Class Description StartParameters A data class wrapping the parameters necessary to start an OAuth flow for a specific provider GetTokenForProviderParams DiscoveryStartParameters A data class wrapping the parameters necessary to start an OAuth flow for a specific provider GetTokenForProviderParams Data class used for wrapping parameters to start a third party OAuth flow and retrieve a token DiscoveryAuthenticateParameters A data class wrapping the parameters necessary to authenticate an OAuth Discovery flow AuthenticateParameters A data class wrapping the parameters necessary to authenticate an OAuth flow -
Interface Summary Interface Description Provider An interface describing the methods and parameters available for starting an OAuth or OAuth discovery flow for a specific provider ProviderDiscovery An interface describing the methods and parameters available for starting an OAuth discovery flow for a specific provider Discovery An interface describing the parameters and methods available for authenticating an OAuth Discovery flow OAuth The OAuth interface provides methods for authenticating a user, via the supported OAuth providers, provided you have configured them within your Stytch Dashboard.