Skip to content

Commit

Permalink
[SDK -61] Access token refresh handler (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
Melisa69 authored Apr 24, 2024
1 parent 1ed8bc2 commit 64c79f4
Show file tree
Hide file tree
Showing 101 changed files with 2,746 additions and 998 deletions.
7 changes: 5 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

apply plugin: 'maven'
apply plugin: 'maven-publish'

buildscript {
Expand All @@ -9,12 +8,13 @@ buildscript {
repositories {
google()
jcenter()
mavenCentral() // Maven Central repository
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.24.16"
// classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.24.16"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -24,6 +24,7 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral() // Maven Central repository
maven { url "https://jitpack.io" }
}
}
84 changes: 62 additions & 22 deletions docs/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,29 @@
</a>
</p>


# Getting started

## Requirements

### Development

- Android Studio 4.2.2 or newer.
- Gradle 6.7.1 or newer.
- Gradle 7.3.2 or newer.
- Kotlin 1.5.1 or newer. **\***

**\*** The SDK is written entirely in Kotlin, but is fully compatible with Java projects.

### Deployment

- Android 5.1 or newer (API Level 21).

## Installation

### Gradle/Maven

1. Ensure you have the JCenter repository in your root `build.gradle` file.<br>(This is automatically added to new Android Studio projects.)

1. Ensure you have the JCenter repository in your root `build.gradle` file.<br>(This is
automatically added to new Android Studio projects.)

2. Include the digi.me SDK as a dependency in your app `build.gradle` file:

`implementation "me.digi:sdk:4.0.14"`
Expand All @@ -52,47 +54,85 @@
2. In Android Studio, import the SDK as a module.
3. In your app `build.gradle`, include the module as a dependency:

`implementation project(":sdk")`
`implementation project(":sdk")`

### Obtaining your Contract ID, Application ID & Private Key

To access the digi.me platform, you need to obtain an AppID for your application. You can get yours by filling out the registration form [here](https://go.digi.me/developers/register).
To access the digi.me platform, you need to obtain an AppID for your application. You can get yours
by filling out the registration form [here](https://go.digi.me/developers/register).

In a production environment, you will also be required to obtain your own Contract ID and Private
Key from digi.me support. However, for demo purposes, we provide example values. You can find
example keys in
our [example applications](https://github.com/digime/digime-sdk-android/tree/master/examples).

### Initializing the SDK

1. Edit Your Resources and Manifest

In a production environment, you will also be required to obtain your own Contract ID and Private Key from digi.me support. However, for demo purposes, we provide example values. You can find example keys in our [example applications](https://github.com/digime/digime-sdk-android/tree/master/examples).
Create strings for your App ID, Contract ID, Private key and Protocol schema.
For example, if your App ID is 1234, Contract ID is 56789 and Private key is 101112 your code looks like the following:

### Initializing the SDK
```xml
<string name="digime_app_id">1234</string>
<string name="digime_contract_id">fb1234</string>
<string name="digime_private_key">56789</string>
<string name="protocol_schema">callback-1234</string>
```

Also, add ConsentBrowserActivity to your Android manifest.

```xml

<activity android:name="me.digi.sdk.ui.ConsentBrowserActivity" android:exported="true"
android:launchMode="singleTop">

Once you have the above, we can initiate the SDK.
<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="digime-ca" />
<data android:host="@string/protocolSchema" tools:ignore="AppLinkUrlError" />
</intent-filter>

You are required to forward invocations of `onActivityResult` through to the SDK so that it may process responses. In any activity that will be responsible for invoking methods on the SDK, override `onActivityResult` as below:
</activity>

```
2. Add onActivityResult
You are required to forward invocations of `onActivityResult` through to the SDK so that it may
process responses. In any activity that will be responsible for invoking methods on the SDK,
override `onActivityResult` as below:

```kotlin
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, responseCode, data)
AppCommunicator.getSharedInstance().onActivityResult(requestCode, responseCode, data)
super.onActivityResult(requestCode, responseCode, data)
AppCommunicator.getSharedInstance().onActivityResult(requestCode, responseCode, data)
}
```

After that we will configure DigiMe client. It's the object you can primarily interface with to use the SDK. It is instantiated with a context, and a `DigiMeConfiguration` object.
3. Configure DigiMe client

After that we will configure DigiMe client. It's the object you can primarily interface with to use
the SDK. It is instantiated with a context, and a `DigiMeConfiguration` object.

**The provided context should always be main application context.**

The `DigiMeConfiguration` object is instantiated with you `AppID`, `Contract ID` and `Private Key`.
The `DigiMeConfiguration` object is instantiated with you `AppID`, `Contract ID` and `Private Key`.

```kotlin
val client: DigiMe by lazy {

val configuration = DigiMeConfiguration(
"your_app_id",
"your_contract_id",
"your_private_key"
)
val configuration = DigiMeConfiguration(
"your_app_id",
"your_contract_id",
"your_private_key"
)

Init(requireContext().applicationContext, configuration)
Init(requireContext().applicationContext, configuration)
}
```

### Using the SDK

* Use digi.me to [request data from your users](read-data-overview.md).
* Use digi.me to [write data to your users](write-data-overview.md).
* Use digi.me to [request data](read-data-overview.html).
* Use digi.me to [write data](write-data-overview.html).
3 changes: 2 additions & 1 deletion examples/saas/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ android {
}

dependencies {
implementation "me.digi:sdk:4.0.10"
// implementation "me.digi:sdk:4.0.12"
implementation project(':sdk')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ class MainRemoteDataAccessImpl(
}
}

override fun pushDataToPostbox(
payloadToWrite: WriteDataPayload,
accessToken: String
): Single<DataWriteResponse> =
Single.create { emitter ->
writeClient.write(
payloadToWrite,
accessToken
) { response: DataWriteResponse?, error ->
error?.let(emitter::onError)
?: emitter.onSuccess(response as DataWriteResponse)
}
}
// override fun pushDataToPostbox(
// payloadToWrite: WriteDataPayload,
// accessToken: String
// ): Single<DataWriteResponse> =
// Single.create { emitter ->
// writeClient.write(
// payloadToWrite,
// accessToken
// ) { response: DataWriteResponse?, error ->
// error?.let(emitter::onError)
// ?: emitter.onSuccess(response as DataWriteResponse)
// }
// }

override fun deleteUsersLibrary(accessToken: String?): Single<Boolean> =
Single.create { emitter ->
Expand Down
3 changes: 2 additions & 1 deletion examples/saasrawdata/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ android {
}

dependencies {
implementation "me.digi:sdk:4.0.13"
// implementation "me.digi:sdk:4.0.13"
implementation project(':sdk')
// Rx
implementation "io.reactivex.rxjava3:rxkotlin:3.0.1"
implementation "io.reactivex.rxjava3:rxandroid:3.0.0"
Expand Down
17 changes: 17 additions & 0 deletions examples/saasrawdata/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="me.digi.saasrawdata">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Expand Down Expand Up @@ -31,6 +32,22 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

<activity
android:name="me.digi.sdk.ui.ConsentBrowserActivity"
android:exported="true"
android:launchMode="singleTop">

<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="digime-ca"/>
<data android:host="@string/protocolSchema" tools:ignore="AppLinkUrlError"/>
</intent-filter>

</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MainActivity : AppCompatActivity() {
val configuration = DigiMeConfiguration(
this.resources.getString(R.string.appId),
this.resources.getString(R.string.writeContractId),
this.resources.getString(R.string.privateKey),
this.resources.getString(R.string.writePrivateKey),
"https://api.digi.me/"
)

Expand All @@ -56,8 +56,8 @@ class MainActivity : AppCompatActivity() {

val configuration = DigiMeConfiguration(
this.resources.getString(R.string.appId),
this.resources.getString(R.string.readContractId),
this.resources.getString(R.string.privateKey),
this.resources.getString(R.string.readRawContractId),
this.resources.getString(R.string.readRawPrivateKey),
"https://api.digi.me/"
)

Expand Down Expand Up @@ -101,23 +101,47 @@ class MainActivity : AppCompatActivity() {
credentials = response?.credentials!!

val fileContent: ByteArray = getFileContent(this, "file.pdf")
val metadata: ByteArray = getFileContent(this, "metadatapdf.json")
val postbox: Data = Data().copy(
key = response.session?.key,
postboxId = response.authResponse?.postboxId,
publicKey = response.authResponse?.publicKey
val metadata = WriteMetadata()
metadata.accounts = listOf(WriteAccount("1"))
metadata.reference = listOf("file.pdf")
metadata.tags = listOf("testTag")
metadata.mimeType = "application/pdf"

val writeDataPayload = WriteDataPayload(
metadata,
fileContent
)

val payloadWriteImage =
WriteDataPayload(postbox, metadata, fileContent, MimeType.IMAGE_PNG)

writeClient.write(
payloadWriteImage,
response.credentials?.accessToken?.value!!
response.credentials?.accessToken?.value!!,
writeDataPayload,
) { _, error ->
progressBar.isVisible = false
if (error == null)
if (error == null) {
readFile.isEnabled = true

val fileContent: ByteArray = getFileContent(this, "file.pdf")

val metadata = WriteMetadata()
metadata.accounts = listOf(WriteAccount("1"))
metadata.reference = listOf("file.pdf")
metadata.tags = listOf("testTag")
metadata.mimeType = "application/pdf"

val writeDataPayload = WriteDataPayload(
metadata,
fileContent
)
writeClient.write(
response.credentials?.accessToken?.value!!,
writeDataPayload,
) { _, error ->
progressBar.isVisible = false
if (error == null)
readFile.isEnabled = true
else
Log.d("MainActivity", "Failed to write data")
}
}
else
Log.d("MainActivity", "Failed to write data")
}
Expand All @@ -129,9 +153,21 @@ class MainActivity : AppCompatActivity() {
}

private fun readFile() {

val scope = CaScope()

val metadata = MetadataScope()
metadata.mimeType = listOf("application/pdf")

val metadataCriteria = MetadataCriteria()
metadataCriteria.metadata = metadata

val criteria = listOf(metadataCriteria)
scope.criteria = criteria

readClient.authorizeAccess(
this,
null,
scope,
credentials,
null

Expand Down
Loading

0 comments on commit 64c79f4

Please sign in to comment.