Casdoor's SDK for Android will allow you to easily connect your application to the Casdoor authentication system without having to implement it from scratch. Casdoor SDK is simple to use. We will show you the steps below.
Add the following dependency to your app's build.gradle file:
dependencies {
implementation 'org.casdoor:casdoor-android-sdk:x.x.x' // not upload to maven yet...
}
Initialization requires 5 parameters, which are all str type:
Name (in order) | Must | Description |
---|---|---|
endpoint | Yes | Casdoor Server Url, such as http://localhost:8000 |
clientID | Yes | Application.clientID |
appName | Yes | Application.name |
apiEndpoint | NO | Casdoor Api Url, default endpoint + "/api/" |
organizationName | Yes | Organization name |
val casdoorConfig = CasdoorConfig(
endpoint = "http://localhost:8000",
clientID = "ced4d6db2f4644b85a75",
organizationName = "organization_6qvtvh",
redirectUri = "casdoor://callback",
appName = "application_y38644"
)
The Casdoor Contains all APIs
val casdoor = Casdoor(casdoorConfig)
At this point, we should use some ways to verify with the Casdoor server.
To start, we want you understand clearly the verification process of Casdoor.
The following paragraphs will mention your app that wants to use Casdoor as a means
of verification as APP
, and Casdoor as Casdoor
.
APP
will send a request to Casdoor
. Since Casdoor
is a UI-based OAuth
provider, you cannot use request management service like Postman to send a URL
with parameters and get back a JSON file.
casdoor-android-sdk support the url,you can use in webview or browser to verify.
casdoor.getSignInUrl()
Hints:
redirect_uri
is the URL that yourAPP
is configured to listen to the response fromCasdoor
. For example, if yourredirect_uri
iscasdoor://callback
, then Casdoor will send a request to this URL along with two parameterscode
andstate
, which will be used in later steps for authentication.state
is usually your Application's name, you can find it under theApplications
tab inCasdoor
, and the leftmostName
column gives each application's name.- The authorize URL allows the user to connect to a provider and give access to your application.
- After Casdoor verification passed, it will be redirected to your
redirect_uri
, likecasdoor://callback?code=xxx&state=yyyy
.you can catch it and get thecode
andstate
, then callrequestOauthAccessToken()
and parse out jwt token.