Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using PowerAuthSDK 1.9.0+ #59

Merged
merged 7 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
root = true

[*{kt,kts}]

# sometimes this is good for readibility
ktlint_standard_string-template = disabled

# sometimes this is good thing when a lot of code is packed
ktlint_standard_no-empty-first-line-in-method-block = disabled

# maybe in the future
ktlint_standard_spacing-between-declarations-with-comments = disabled

# this is no JS or TS
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled

# not sure about this, but i dont like it :)
ktlint_standard_colon-spacing = disabled

# this is nitpicking
ktlint_standard_import-ordering = disabled
ktlint_standard_no-wildcard-imports = disabled

# sometimes this is good thing
ktlint_standard_filename = disabled
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ on:
- main
- release/*
pull_request:
schedule:
- cron: '25 6 * * *'

jobs:
build:
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Lint

on:
push:
branches:
- develop
- release/*
pull_request:

jobs:
ktlint:
name: ktlint
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v4
- name: Run lint script
run: ./scripts/lint.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.externalNativeBuild
jd-gui.cfg
.java-version
ktlint

# release folder
/release
Expand Down
71 changes: 50 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ repositories {
implementation "com.wultra.android.powerauth:powerauth-networking:1.x.y"
```

### Guaranteed PowerAuth Compatibility

| WPN SDK | PowerAuth SDK |
|-------------------|---------------|
| `1.5.x` | `1.9.x` |
| `1.4.x` | `1.8.x` |
| `1.3.x` | `1.8.x` |
| `1.1.x` - `1.2.x` | `1.7.x` |
| `1.0.x` | `1.6.x` |

## Open Source Code

The code of the library is open source and you can freely browse it in our GitHub at [https://github.com/wultra/networking-android](https://github.com/wultra/networking-android/#docucheck-keep-link)
Expand Down Expand Up @@ -111,14 +121,36 @@ class MyServiceApi(

Each endpoint you will target with your project must be defined for the service as an `Endpoint` instance. There are several types of endpoints based on the PowerAuth signature that is required.

### End To End Encryption

If the endpoint is end-to-end encrypted, you need to configure it in the constructor. Default value is set to `E2EEConfiguration.NOT_ENCRYPTED`.

Possible values are:

```kotlin
/** End to end encryption configuration for an endpoint. */
enum class E2EEConfiguration {
/** Endpoint is encrypted with the application scope. */
APPLICATION_SCOPE,
/** Endpoint is encrypted with the activation scope. */
ACTIVATION_SCOPE,
/** Endpoint is not encrypted. */
NOT_ENCRYPTED
}
```

<!-- begin box info -->
Whether an endpoint is encrypted or not is based on its backend definition.
<!-- end -->

### Signed endpoint `EndpointSigned`

For endpoints that are __signed__ by PowerAuth signature and can be end-to-end encrypted.

Example:

```kotlin
val mySignedEndpoint = EndpointSigned<MyRequest, MyResponse>("api/my/endpoint/path", "/endpoint/uriId")
val mySignedEndpoint = EndpointSigned<MyRequest, MyResponse>("api/my/endpoint/path", "/endpoint/uriId", E2EEConfiguration.NOT_ENCRYPTED)
// uriId is defined by the endpoint issuer - ask your server developer/provider
```

Expand All @@ -131,7 +163,7 @@ More info for token-based authentication [can be found here](https://github.com/
Example:

```kotlin
val myTokenEndpoint = EndpointSignedWithToken<MyRequest, MyResponse>("api/my/endpoint/path", "possession_universal")
val myTokenEndpoint = EndpointSignedWithToken<MyRequest, MyResponse>("api/my/endpoint/path", "possession_universal", E2EEConfiguration.NOT_ENCRYPTED)

// token name (`possession_universal` in this case) is the name of the token as stored in the PowerAuthSDK
// more info can be found in the PowerAuthSDK documentation
Expand All @@ -146,7 +178,7 @@ For endpoints that are __not signed__ by PowerAuth signature but can be end-to-e
Example:

```kotlin
val myBasicEndpoint = EndpointBasic<MyRequest, MyResponse>("api/my/endpoint/path")
val myBasicEndpoint = EndpointBasic<MyRequest, MyResponse>("api/my/endpoint/path", E2EEConfiguration.NOT_ENCRYPTED)
```

## Creating an HTTP request
Expand All @@ -158,7 +190,6 @@ To create an HTTP request to your endpoint, you need to call the `Api.post` meth
- `auth` - `PowerAuthAuthentication` instance that will sign the request
- this parameter is missing for the basic and token endpoints
- `headers` - custom HTTP headers, `null` by default
- `encryptor` - End to End encryptor in case that the encryption is required, `null` by default
- `okHttpInterceptor` - OkHttp interceptor to intercept requests eg. for logging purposes, `null` by default
- `listener` - result listener

Expand All @@ -175,7 +206,7 @@ class SampleRequest(requestObject: SampleRequestData): ObjectRequest<SampleReque
class SampleResponse(responseObject: SampleResponseData, status: Status): ObjectResponse<SampleResponseData>(responseObject, status)

// endpoint configuration
val myEndpoint = EndpointSigned<SampleRequest, SampleResponse>("api/my/endpoint/path", "/my/endoint/uriId")
val myEndpoint = EndpointSigned<SampleRequest, SampleResponse>("api/my/endpoint/path", "/my/endoint/uriId", E2EEConfiguration.NOT_ENCRYPTED)

// Authentication, for example purposes, expect user PIN 1111
val auth = PowerAuthAuthentication.possessionWithPassword("1111")
Expand All @@ -190,8 +221,6 @@ post(
auth,
// custom HTTP headers
hashMapOf(Pair("MyCustomHeader","Value"))
// encrypt with the application scope. null if not encrypted (usual case)
powerAuthSDK.eciesEncryptorForApplicationScope,
// no HTTP interceptor
null,
// handle response or error
Expand Down Expand Up @@ -221,20 +250,20 @@ Each `ApiError ` has an optional `error` property for why the error was created.

#### Known common API errors

| Option Name | Description |
|---|---|
| `ERROR_GENERIC` | When unexpected error happened |
| `POWERAUTH_AUTH_FAIL` | General authentication failure (wrong password, wrong activation state, etc...) |
| `INVALID_REQUEST` | Invalid request sent - missing request object in the request |
| `INVALID_ACTIVATION` | Activation is not valid (it is different from configured activation) |
| `INVALID_APPLICATION` | Invalid application identifier is attempted for operation manipulation. |
| `INVALID_OPERATION` | Invalid operation identifier is attempted for operation manipulation. |
| `ERR_ACTIVATION` | Error during activation |
| `ERR_AUTHENTICATION` | Error in case that PowerAuth authentication fails |
| `ERR_SECURE_VAULT` | Error during secure vault unlocking |
| `ERR_ENCRYPTION` | Returned in case encryption or decryption fails |
| `TOO_MANY_REQUESTS` | Too many same requests |
| `REMOTE_COMMUNICATION_ERROR` | Communication with remote system failed |
| Option Name | Description |
|------------------------------|-------------------------------------------------------------------------------------------|
| `ERROR_GENERIC` | Network error that indicates a generic network issue (for example server internal error). |
| `POWERAUTH_AUTH_FAIL` | General authentication failure (wrong password, wrong activation state, etc...) |
| `INVALID_REQUEST` | Invalid request sent - missing request object in the request |
| `INVALID_ACTIVATION` | Activation is not valid (it is different from configured activation) |
| `INVALID_APPLICATION` | Invalid application identifier is attempted for operation manipulation. |
| `INVALID_OPERATION` | Invalid operation identifier is attempted for operation manipulation. |
| `ERR_ACTIVATION` | Error during activation |
| `ERR_AUTHENTICATION` | Error in case that PowerAuth authentication fails |
| `ERR_SECURE_VAULT` | Error during secure vault unlocking |
| `ERR_ENCRYPTION` | Returned in case encryption or decryption fails |
| `TOO_MANY_REQUESTS` | Too many same requests |
| `REMOTE_COMMUNICATION_ERROR` | Communication with remote system failed |

#### Known specific API errors

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ allprojects {

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
}
4 changes: 2 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plugins{
plugins {
`kotlin-dsl`
}

Expand All @@ -16,4 +16,4 @@ val dokkaVersion: String by System.getProperties()
dependencies {
implementation("com.android.tools.build", "gradle", androidPluginVersion)
implementation(kotlin("gradle-plugin", kotlinVersion))
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ object Constants {
const val minSdkVersion = 21
const val buildToolsVersion = "33.0.2"
}
}
}
23 changes: 16 additions & 7 deletions library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,30 @@ android {
suppressWarnings = false
}
}

// Custom ktlint script
tasks.register("ktlint") {
logger.lifecycle("ktlint")
exec {
commandLine = listOf("./../scripts/lint.sh", "--no-error")
}
}

// Make ktlint run before build
tasks.getByName("preBuild").dependsOn("ktlint")
}

dependencies {
// Bundled
implementation("org.jetbrains.kotlin:kotlin-stdlib:${Constants.BuildScript.kotlinVersion}")
implementation("androidx.annotation:annotation:1.7.0")
implementation("com.google.code.gson:gson:2.10.1")
implementation("androidx.annotation:annotation:1.8.2")
implementation("com.google.code.gson:gson:2.11.0")
implementation("com.jakewharton.threetenabp:threetenabp:1.1.1")
// DO NOT UPGRADE OKHTTP ABOVE 3.12.X! Version 3.12 is the last version supporting TLS 1 and 1.1
// If upgraded, the app will crash on android 4.4
implementation("com.squareup.okhttp3:okhttp:3.12.13")
implementation("com.squareup.okhttp3:okhttp:4.9.3")

// Dependencies
compileOnly("com.wultra.android.powerauth:powerauth-sdk:1.8.0")
compileOnly("com.wultra.android.powerauth:powerauth-sdk:1.9.2")
compileOnly("io.getlime.core:rest-model-base:1.2.0")
}

apply("android-release-aar.gradle")
apply("android-release-aar.gradle")
2 changes: 1 addition & 1 deletion library/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
# and limitations under the License.
#

VERSION_NAME=1.4.1-SNAPSHOT
VERSION_NAME=1.5.0-SNAPSHOT
GROUP_ID=com.wultra.android.powerauth
ARTIFACT_ID=powerauth-networking
Loading