Android™
Android™
curl Update Local Manager Secrets
See more CURL Examples
Demonstrates how to initially write secrets to the local manager that will later be used in curl commands. On Windows, this refers to the Windows Credential Manager, and on macOS, it refers to the Apple Keychain.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// This example will store 3 secrets in the local manager.
// On Windows, this refers to the Windows Credential Manager, and on macOS, it refers to the Apple Keychain.
// These secrets will be used at a later point in time in curl commands,
// as shown in this example: Using Local Manager Secrets with curl
// Also see: Chilkat v11.5.0 — Secrets Integration
// and also: Chilkat Secrets API
CkSecrets secrets = new CkSecrets();
CkJsonObject json = new CkJsonObject();
json.UpdateString("appName","sharepoint");
json.UpdateString("service","oauth2");
json.UpdateString("username","client_id");
// These are not actual/real values..
success = secrets.UpdateSecretStr(json,"4afc67c5-6d3f-4ed0-91c7-5d239c78bff7");
if (success == false) {
Log.i(TAG, secrets.lastErrorText());
return;
}
json.UpdateString("username","client_secret");
success = secrets.UpdateSecretStr(json,"Rlh8Q~xaP10Dw-goWQDLXrRJfYAFVW1hHauvfhO6");
if (success == false) {
Log.i(TAG, secrets.lastErrorText());
return;
}
json.UpdateString("username","token_endpoint");
success = secrets.UpdateSecretStr(json,"https://login.microsoftonline.com/5f410b89-177f-40b3-9d66-ac519c728025/oauth2/v2.0/token");
if (success == false) {
Log.i(TAG, secrets.lastErrorText());
return;
}
// -----------------------------------------------------------------------------------------------------------
// The above secrets would be accessed like this:
CkJsonObject json2 = new CkJsonObject();
json2.put_EnableSecrets(true);
// Chilkat sees the secret specification string (beginning with "!!") and resolves from the local manager.
json2.UpdateString("x","!!sharepoint|oauth2|client_id");
Log.i(TAG, "x = " + json2.stringOf("x"));
json2.UpdateString("y","!!sharepoint|oauth2|client_secret");
Log.i(TAG, "y = " + json2.stringOf("y"));
json2.UpdateString("z","!!sharepoint|oauth2|token_endpoint");
Log.i(TAG, "z = " + json2.stringOf("z"));
// You can see the values retrieved from the local manager:
// x = 4afc67c5-6d3f-4ed0-91c7-5d239c78bff7
// y = Rlh8Q~xaP10Dw-goWQDLXrRJfYAFVW1hHauvfhO6
// z = https://login.microsoftonline.com/5f410b89-177f-40b3-9d66-ac519c728025/oauth2/v2.0/token
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}