Skip to content

Commit

Permalink
Fix #443: Add support for Huawei Mobile Services (#750)
Browse files Browse the repository at this point in the history
* Fix #443: Add support for Huawei Mobile Services
  • Loading branch information
banterCZ authored Feb 8, 2024
1 parent a2e206f commit fef8466
Show file tree
Hide file tree
Showing 52 changed files with 2,072 additions and 126 deletions.
18 changes: 17 additions & 1 deletion docs/Configuration-Properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The Push Server uses the following public configuration properties:
| `powerauth.push.service.apns.idlePingInterval` | `60000` | Interval in milliseconds specifying the frequency of APNS ping calls in idle state |
| `powerauth.push.service.apns.concurrentConnections` | `1` | Push message concurrency settings |

# FCM Configuration
## FCM Configuration

| Property | Default | Note |
|---|---|---|
Expand All @@ -72,6 +72,22 @@ The Push Server uses the following public configuration properties:
| `powerauth.push.service.fcm.sendMessageUrl` | `https://fcm.googleapis.com/v1/projects/%s/messages:send` | Default URL for the FCM service |
| `powerauth.push.service.fcm.connect.timeout` | `5000` | Push message gateway connect timeout in milliseconds |

## HMS Configuration

| Property | Default | Note |
|---------------------------------------------------|---------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| `powerauth.push.service.hms.proxy.enabled` | `false` | Flag indicating if the communication needs to go through proxy. |
| `powerauth.push.service.hms.proxy.host` | `127.0.0.1` | Proxy host. |
| `powerauth.push.service.hms.proxy.port` | `8080` | Proxy port. |
| `powerauth.push.service.hms.proxy.username` | `_empty_` | Proxy username. |
| `powerauth.push.service.hms.proxy.password` | `_empty_` | Proxy password. |
| `powerauth.push.service.hms.dataNotificationOnly` | `false` | Flag indicating that HMS service should never use "notification" format, only a data format with extra payload representing the notification. |
| `powerauth.push.service.hms.sendMessageUrl` | `https://push-api.cloud.huawei.com/v2/%s/messages:send` | Default URL for the HMS service. |
| `powerauth.push.service.hms.tokenUrl` | `https://oauth-login.cloud.huawei.com/oauth2/v3/token` | Default URL for the HMS OAuth service to obtain an access token. |
| `powerauth.push.service.hms.connect.timeout` | `5s` | Push message gateway connect timeout. |
| `powerauth.push.service.hms.response.timeout` | `60s` | Push message gateway maximum duration allowed between each network-level read operations. |
| `powerauth.push.service.hms.max-idle-time` | `200s` | Push message gateway ConnectionProvider max idle time. |

## Correlation HTTP Header Configuration

| Property | Default | Note |
Expand Down
1 change: 1 addition & 0 deletions docs/Migration-Instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

This page contains PowerAuth Push Server migration instructions.

- [PowerAuth Push Server 1.7.0](./PowerAuth-Push-Server-1.7.0.md)
- [PowerAuth Push Server 1.6.0](./PowerAuth-Push-Server-1.6.0.md)
- [PowerAuth Push Server 1.5.0](./PowerAuth-Push-Server-1.5.0.md)
- [PowerAuth Push Server 1.4.0](./PowerAuth-Push-Server-1.4.0.md)
Expand Down
11 changes: 11 additions & 0 deletions docs/PowerAuth-Push-Server-1.7.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Migration from 1.6.x to 1.7.x

This guide contains instructions for migration from PowerAuth Push Server version `1.6.x` to version `1.7.x`.


## Database Changes


### Huawei Mobile Services

To support HMS, the columns `hms_project_id`, `hms_client_id`, and `hms_client_secret` have been added into the table `push_app_credentials`.
109 changes: 102 additions & 7 deletions docs/Push-Server-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ Send a system status response, with basic information about the running applicat

## Device

Represents mobile device with iOS or Android that is capable to receive a push notification. Device has to first register with APNS or FCM to obtain push token.
Represents mobile device with iOS, Android or Huawei that is capable to receive a push notification.
Device has to first register with APNS, FCM, or HMS to obtain push token.
Then it has to forward the push token to the push server end-point. After that push server is able to send push notification to the device.

<!-- begin api POST /push/device/create -->
Expand Down Expand Up @@ -181,7 +182,7 @@ _Note: Since this endpoint is usually called by the back-end service, it is not

- `appId` - Application that device is using.
- `token` - Identifier for device.
- `platform` - `ios`, `android`
- `platform` - `ios`, `android`, `huawei`
- `activationId` - Activation identifier

#### Response 200
Expand Down Expand Up @@ -231,7 +232,7 @@ _Note: Since this endpoint is usually called by the back-end service, it is not

- `appId` - Application that device is using.
- `token` - Identifier for device.
- `platform` - `ios`, `android`
- `platform` - `ios`, `android`, `huawei`
- `activationIds` - Associated activation identifiers

#### Response 200
Expand Down Expand Up @@ -412,6 +413,12 @@ Send a single push message to given user via provided application, optionally to
"pending": 0,
"failed": 0,
"total": 1
},
"huawei": {
"sent": 1,
"pending": 0,
"failed": 0,
"total": 1
}
}
}
Expand Down Expand Up @@ -533,6 +540,12 @@ Sends a message batch - each item in the batch represents a message to given use
"pending": 0,
"failed": 0,
"total": 1
},
"huawei": {
"sent": 1,
"pending": 0,
"failed": 0,
"total": 1
}
}
}
Expand Down Expand Up @@ -1108,7 +1121,8 @@ Get list of all applications.
{
"appId": "mobile-app",
"ios": true,
"android": true
"android": true,
"huawei": true
}
]
}
Expand Down Expand Up @@ -1146,7 +1160,8 @@ Get list of applications which have not been configured yet.
{
"appId": "mobile-app-other",
"ios": null,
"android": null
"android": null,
"huawei": null
}
]
}
Expand Down Expand Up @@ -1193,12 +1208,14 @@ Get detail of an application.
"application": {
"appId": "mobile-app",
"ios": true,
"android": true
"android": true,
"huawai": true
},
"iosBundle": "some.bundle.id",
"iosKeyId": "KEYID123456",
"iosTeamId": "TEAMID123456",
"androidProjectId": "PROJECTID123"
"androidProjectId": "PROJECTID123",
"huaweiProjectId": "HMS123"
}
}
```
Expand Down Expand Up @@ -1405,6 +1422,84 @@ Remove FCM configuration for Android push messages.
```
<!-- end -->

<!-- begin api PUT /admin/app/huawei/update -->
### Update Huawei Configuration

Update an Huawei configuration.


#### Request

<!-- begin remove -->
<table>
<tr>
<td>Method</td>
<td><code>POST / PUT</code></td>
</tr>
<tr>
<td>Resource URI</td>
<td>/admin/app/huawei/update</td>
</tr>
</table>
<!-- end -->

```json
{
"requestObject": {
"appId": "mobile-app",
"projectId": "PROJECTID123",
"clientId": "oAuth 2.0 client ID",
"clientSecret": "oAuth 2.0 client secret"
}
}
```

#### Response 200

```json
{
"status": "OK"
}
```
<!-- end -->

<!-- begin api DELETE /admin/app/huawei/remove -->
### Remove Huawei Configuration

Remove configuration for Huawei push messages.

#### Request

<!-- begin remove -->
<table>
<tr>
<td>Method</td>
<td><code>POST / DELETE</code></td>
</tr>
<tr>
<td>Resource URI</td>
<td>/admin/app/huawei/remove</td>
</tr>
</table>
<!-- end -->

```json
{
"requestObject": {
"appId": "mobile-app"
}
}
```

#### Response 200

```json
{
"status": "OK"
}
```
<!-- end -->

## Message Inbox

When communicating with your users, you can use the message inbox to store messages for users. Inbox is not responsible
Expand Down
37 changes: 35 additions & 2 deletions docs/Push-Server-Administration.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ curl --request POST \
"requestObject": {
"appId": 1,
"includeIos": true,
"includeAndroid": true
"includeAndroid": true,
"includeHuawei": true
}
}'
```
Expand Down Expand Up @@ -136,7 +137,39 @@ curl --request DELETE \
}'
```

Set the `appId` value for the Push Server application ID you want to update.
Set the `appId` value for the Push Server application ID you want to delete.


### Update Huawei Configuration

```sh
curl --request POST \
--url http://localhost:8080/powerauth-push-server/admin/app/huawei/update \
--json '{
"requestObject": {
"appId": 1,
"projectId": "projectId",
"clientId": "oAuth 2.0 client ID",
"clientSecret": "oAuth 2.0 client secret"
}
}'
```

Set the `appId` value for Push Server application ID to want to update.

### Remove Huawei Configuration

```sh
curl --request DELETE \
--url http://localhost:8080/powerauth-push-server/admin/app/huawei/remove \
--json '{
"requestObject": {
"appId": 1
}
}'
```

Set the `appId` value for the Push Server application ID you want to delete.

## Administration using SQL Database

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd">

<changeSet id="1" logicalFilePath="powerauth-push-server/1.7.x/20240119-push_app_credentials-hms.xml" author="Lubos Racansky">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="push_app_credentials" columnName="hms_project_id"/>
<columnExists tableName="push_app_credentials" columnName="hms_client_id"/>
<columnExists tableName="push_app_credentials" columnName="hms_client_secret"/>
</not>
</preConditions>
<comment>Add hms_project_id, hms_client_id, and hms_client_secret columns to push_app_credentials</comment>
<addColumn tableName="push_app_credentials">
<column name="hms_project_id" type="varchar(255)" remarks="Project ID defined in Huawei AppGallery Connect." />
<column name="hms_client_id" type="varchar(255)" remarks="Huawei OAuth 2.0 Client ID." />
<column name="hms_client_secret" type="varchar(255)" remarks="Huawei OAuth 2.0 Client Secret." />
</addColumn>
</changeSet>


</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd">

<include file="20240119-push_app_credentials-hms.xml" relativeToChangelogFile="true" />

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

<include file="1.4.x/db.changelog-version.xml" relativeToChangelogFile="true" />
<include file="1.5.x/db.changelog-version.xml" relativeToChangelogFile="true" />
<include file="1.7.x/db.changelog-version.xml" relativeToChangelogFile="true" />

</databaseChangeLog>
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludedGroups>external-service</excludedGroups>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,14 @@ public ObjectResponse<GetApplicationListResponse> getUnconfiguredApplicationList

/**
* Get detail for an application credentials entity.
* @param appId Application credentials entity ID.
* @param includeIos Whether to include iOS details.
* @param includeAndroid Whether to include Android details.
* @param request Application detail request.
* @return Application credentials entity detail.
* @throws PushServerClientException Thrown when communication with Push Server fails.
*/
public ObjectResponse<GetApplicationDetailResponse> getApplicationDetail(String appId, boolean includeIos, boolean includeAndroid) throws PushServerClientException {
GetApplicationDetailRequest request = new GetApplicationDetailRequest(appId, includeIos, includeAndroid);
logger.info("Calling push server to retrieve application detail, ID: {} - start", appId);
public ObjectResponse<GetApplicationDetailResponse> getApplicationDetail(final GetApplicationDetailRequest request) throws PushServerClientException {
logger.info("Calling push server to retrieve application detail, ID: {} - start", request.getAppId());
final ObjectResponse<GetApplicationDetailResponse> response = postObjectImpl("/admin/app/detail", new ObjectRequest<>(request), GetApplicationDetailResponse.class);
logger.info("Calling push server to retrieve application detail, ID: {} - finish", appId);
logger.info("Calling push server to retrieve application detail, ID: {} - finish", request.getAppId());
return response;
}

Expand Down Expand Up @@ -592,6 +589,35 @@ public Response removeAndroid(String appId) throws PushServerClientException {
return response;
}

/**
* Update Huawei details for an application credentials entity.
*
* @param request Update Huawei request.
* @return Response from server.
* @throws PushServerClientException Thrown when communication with Push Server fails.
*/
public Response updateHuawei(final UpdateHuaweiRequest request) throws PushServerClientException {
logger.info("Calling push server to update Huawei, ID: {} - start", request.getAppId());
final Response response = putObjectImpl("/admin/app/huawei/update", new ObjectRequest<>(request));
logger.info("Calling push server to update Huawei, ID: {} - finish", request.getAppId());
return response;
}

/**
* Remove Huawei record from an application credentials entity.
*
* @param appId Application credentials entity ID.
* @return Response from server.
* @throws PushServerClientException Thrown when communication with Push Server fails.
*/
public Response removeHuawei(String appId) throws PushServerClientException {
final RemoveHuaweiRequest request = new RemoveHuaweiRequest(appId);
logger.info("Calling push server to remove Huawei, ID: {} - start", appId);
final Response response = postObjectImpl("/admin/app/huawei/remove", new ObjectRequest<>(request));
logger.info("Calling push server to remove Huawei, ID: {} - finish", appId);
return response;
}

/**
* Post a message to an inbox of provided user.
* @param request Request with the message detail.
Expand Down
Loading

0 comments on commit fef8466

Please sign in to comment.