Skip to content

SPIDlibraryAndroid is a library for logging in via SPID through several different identity providers.

License

Notifications You must be signed in to change notification settings

INPS-it/SPIDlibraryAndroid

Repository files navigation

SPIDlibraryAndroid

SPIDlibraryAndroid is a library for logging in via SPID through several different identity providers.

Requirements

  • Android 4.4+

Usage

  1. Add dependency to your project:
repositories {
   maven {
       url = "https://maven.pkg.github.com/INPS-it/SPIDlibraryAndroid"
       credentials {
           username = GITHUB_USER
           password = GITHUB_TOKEN
       }
   }
}
dependencies {
    implementation("it.inps.spid:library:1.0.10")
}
  1. Declare a variable to register the IdentityProviderSelectorActivityContract contract using the registerForActivityResult(I) method which will give a SpidResult object as a return value:
private val startSpidFlow = registerForActivityResult(IdentityProviderSelectorActivityContract()) { spidResult ->
    when (spidResult.spidEvent) {
        SpidEvent.GENERIC_ERROR -> { /* TODO */ }
        SpidEvent.NETWORK_ERROR -> { /* TODO */ }
        SpidEvent.SESSION_TIMEOUT -> { /* TODO */ }
        SpidEvent.SPID_CONFIG_ERROR -> { /* TODO */ }
        SpidEvent.SUCCESS -> { /* spidResult.spidReponse available */ }
        SpidEvent.USER_CANCELLED -> { /* TODO */ }
    }
}

The SpidResult object consists of a SpidEvent object and an optional SpidResponse object. The SpidResponse object is only available in case of successful login.

  1. Create a SpidParams.Config object containing the authPageUrl url, the callbackPageUrl url and an optional timeout int value (default value: 30sec):
val spidConfig = SpidParams.Config(
                    "https://<insert the auth url here>", // TODO
                    "https://<insert the callback url here>", // TODO
                    60
    )
  1. Use the IdentityProvider.Builder() builder to add the identity providers:
val idpList = IdentityProvider.Builder()
                   .addAruba(idpParameter = "<insert the idp parameter here>")
                   .addPoste(idpParameter = "<insert the idp parameter here>")
                   .addTim(idpParameter = "<insert the idp parameter here>")
                   .addCustomIdentityProvider(
                           "CUSTOM IDENTITY PROVIDER",
                           R.drawable.ic_spid_idp_custom,
                           "<insert the idp parameter here>"
                   )
                   // TODO
                   .build()
  1. Create a SpidParams object using the spidConfig and idpList objects and call the ActivityResultLauncher.launch(I) method:
startSpidFlow.launch(SpidParams(spidConfig, idpList))

License

SPIDlibraryAndroid is released under the BSD 3-Clause License. See LICENSE for details.

About

SPIDlibraryAndroid is a library for logging in via SPID through several different identity providers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages