-
アプリのstrings.xmlに次の文字列を追加します:
<string name='iam_portal_url'>
https://accounts.zohoportal.com</string><!--利用しているデータセンターのアカウントURLを入力してください。例:EUのユーザーの場合は
https://accounts.zohoportal.eu-->を使用します。
<string name='c_id'> GENERATED CLIENT ID </string>
<string name='c_secret'> GENERATED CLIENT SECRET ID </string>
<string name='c_portal'> PORTAL ID </string>
<string name='redir_url'> REGISTERED REDIRECT URI</string>
-
アプリクラスまたはアクティビティクラスのoncreateメソッドで、次のようにAccounts SDKを初期化します:
IAMClientSDK.getInstance(this).init(scopes)
ここで、scopesには次の値を指定します:'aaaserver.profile.READ,zohocontacts.userphoto.READ,ZohoContacts.contactapi.READ,
ZohoCreator.meta.CREATE,ZohoCreator.meta.READ,ZohoCreator.meta.UPDATE,
ZohoCreator.meta.DELETE,ZohoCreator.data.CREATE,ZohoCreator.data.READ,
ZohoCreator.data.UPDATE,ZohoCreator.data.DELETE,ZohoCRM.modules.READ,
ZohoCRM.users.READ'
メモ:バージョン1.4以降では、スコープの一覧が更新されています。
-
HandleRedirectActivityという名前のアクティビティを作成し、そのoncreateメソッドに次のコードを追加します:
IAMClientSDK.getInstance(this).handleRedirection(this)
-
AndroidManifest.xmlファイルに次のコードを追加します:
<activity android:name='.HandleRedirectActivity' android:exported='true'>
<intent-filter>
<action android:name='android.intent.action.VIEW' />
<category android:name='android.intent.category.DEFAULT' />
<category android:name='android.intent.category.BROWSABLE' />
<data android:scheme='<REDIRECT_URI_WITHOUT_COLON_AND_SLASH>' />
</intent-filter>
</activity>
-
ログイン画面を開くために、次のコードスニペットを追加します:
クライアントの作成時に[JWTトークンを生成]を有効にした場合は、[JWTトークンあり]タブのコードスニペットを追加します。それ以外の場合は、[JWTトークンなし]タブのコードを追加します。
JWTトークンなし
val sdk = IAMClientSDK.getInstance(applicationContext)
if (!sdk.isUserSignedIn) {
sdk.presentLoginScreen(this, object : IAMTokenCallback {
override fun onTokenFetchInitiated() {
}
override fun onTokenFetchComplete(zohoToken: IAMToken) {
//<This method will be called after user logged-in successfully>
}
override fun onTokenFetchFailed(zohoErrorCodes: IAMErrorCodes) {
//<This method will be called if any error occurred in the login. You will receive the error code in this callback.>
}
}, null)
} else {
// start intent to your first activity
}
JWTトークンあり
val sdk = IAMClientSDK.getInstance(applicationContext)
if (!sdk.isUserSignedIn) {
IAMClientSDK.getInstance(context).getRemoteTokenWithJWTToken(jwtToken, <PORTAL ID>, object : IAMTokenCallback {
override fun onTokenFetchInitiated() {
}
override fun onTokenFetchComplete(token: IAMToken) {
}
override fun onTokenFetchFailed(errorCode: IAMErrorCodes) {
if (errorCode == IAMErrorCodes.user_cancelled) {
return
}
//This method will be called if any error occurred in the login. You will receive the error code in this callback.
}
})
} else {
// start intent to your first activity
}
-
Creatorの認証インターフェイスZCOauthHelperを次のように実装します:
class ZCAuthImpl(private val context: Context) : ZCOauthHelper {
@Throws(ZCException::class)
override suspend fun getAccessToken(): String? {
return suspendCoroutine { continuation ->
IAMClientSDK.getInstance(context).getToken(object : IAMTokenCallback {
override fun onTokenFetchInitiated() {
}
override fun onTokenFetchComplete(token: IAMToken) {
continuation.resumeWith(Result.success(token.token))
}
override fun onTokenFetchFailed(errorCode: IAMErrorCodes) {
continuation.resumeWith(Result.success(null))
}
})
}
}
override fun getInitialScopes(context: Context): String {
return ''
}
override fun isUserSignedIn(): Boolean {
return IAMClientSDK.getInstance(context).isUserSignedIn
}
override fun getUserData(): Any? {
return null
}
override fun getTransformedUrl(url: String): String {
return url
}
override fun checkAndLogout(): Boolean {
return false
}
override fun isEnhanceTokenNeeded(newScopes: String): Boolean {
return false
}
override fun enhanceToken(tokenHelper: ZCOauthHelper.ZCOAuthTokenHelper, newScopes: String) {
}
override fun enhanceTokenWithOnDemandScope(tokenHelper: ZCOauthHelper.ZCOAuthTokenHelper) {
}
}
-
アプリまたはアクティビティのoncreateメソッドに次のコードスニペットを追加し、Creator SDKに認証インターフェイスのインスタンスを設定します:
ZCAPIUtil.setOAuthHelper(ZCAuthImpl(applicationContext))
-
アプリまたはアクティビティのoncreateメソッドでZohoCreator SDKを初期化します:
ZCAPIUtil.initialize(applicationContext)