Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Integrate New Apps with Radar Platform

...

POST <baseUrl>/managementportal/oauth/token
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token&refresh_token=<your_refresh_token>

And HTTP Basic Authorization with OAuth client Id and OAuth client secret as the username and password respectively.

...

{
  "access_token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWJqZWN0X2lkIjoxLCJzdWIiOiJzdWItMSIsInNvdXJjZXMiOltdLCJ1c2VyX25hbWUiOiJzdWItMSIsInJvbGVzIjpbInJhZGFyLTE6Uk9MRV9QQVJUSUNJUEFOVCJdLCJpc3MiOiJNYW5hZ2VtZW50UG9ydGFsIiwiYXV0aG9yaXRpZXMiOlsiUk9MRV9QQVJUSUNJUEFOVCJdLCJjbGllbnRfaWQiOiJUSElOQy1JVCIsImF1ZCI6WyJyZXNfZ2F0ZXdheSIsInJlc19NYW5hZ2VtZW50UG9ydGFsIl0sInNjb3BlIjpbInJlYWQiLCJ3cml0ZSJdLCJleHAiOjE1MDU4Nzg0OTIsImlhdCI6MTUwNTgzNTI5MiwianRpIjoiYWRiMjg1YTQtM2IwZi00NTkzLTg4ZWYtYWQzOTU2NjMwMDdmIn0.K_JbTxd8oQAJmr7yDbUKGkfWWYrOAZI4z6lN_-09nsCinf4atYiC53kGgnClZ4yYdUuPNMpTgRR0slGU8u8CYuWx_A2JBT_hyeQHqWtTh96s4Rd39WljGtKELMDnLR1ojqKi83yFEvQD7Jq83fMc-3KurU5h9CpDiPdw2nmQIFiss0x8i2WJjhYaPY0Ye3nxJueFZfxM6DDUQxIDJL5cZeBcM210trTGzw8VnBkA1V4j2fS_VLyZqGoslmcZYWHKt-dtGr8pa5AASAg2hXhNcVW9AULvq6fkGm6thZxiLSc1c0LcwywgVleSsHHGQYcov4nhaj-DRGXIZecrRggKrCMPyM56DVMxMAtToHZEoC8LZN8s-eDAjWtOQ2U5D5_JYm6_fVBOH-bILpLeNH-xKwB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1KqmSRHiMXKLcFRPJEbvn8xNf73SGZUpWyi4fg1ELuahtmqJcZYkppeDrKBbscLyu28YIQM5vMEYaIoTQ9M97zqz9zwiIxIZxG0IOuu-0-lSTV71tEVSsLFor7tdEz-dCdNQNOyibVTvkMgCYFa_uCBQ50MHpyn8zsMu6HsNx6eo40WNHz55agIwru1wwrzWDlr6sKZHQQF0wMwDGnmfSQQgFvKzn-tBp5F1hX1lGk19QmvWaj_fAiRe_zPWEaJDPzQJUMuMvxg2q25TT-h5lKofjauBuxazUGuXRr40G2JZjbEu8Kfg-ifpszV7o8Pxi53Nvc56HMAjsVeolWyqc9dtCF8jZcufTzvZA_sLp7dq2ZAAqAHO6SIlv0fSQiinNGFyEi18HB7TMap9F42NRBnhScCHwtqMFcUOFa6mRFqpmDpec",
  "expires_in" : 43199,
  "scope" : "read write",
  "sub" : "sub-1",
  "sources" : [ ],
  "roles" : [ "radar-1:ROLE_PARTICIPANT" ],
  "iss" : "ManagementPortal",
  "iat" : 1505835292,
  "jti" : "adb285a4-3b0f-4593-88ef-ad395663007f"
}

Now, you can parse the access token out of this response and use it in Authorization header with each request. Note that this token will only grant you privileges to the resources related to the paired subject. Add the following to the header to get access with each request-

...

{
    "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJyYWRhcl9yZXN0YXBpIiwiYXVkIjpbInJlc19nYXRld2F5IiwicmVzX01hbmFnZW1lbnRQb3J0YWwiXSwic291cmNlcyI6W10sInNjb3BlIjpbIlNVQkpFQ1QuUkVBRCIsIlBST0pFQ1QuUkVBRCIsIlNPVVJDRS5SRUFEIiwiREVWSUNFVFlQRS5SRUFEIl0sImlzcyI6Ik1hbmFnZW1lbnRQb3J0YWwiLCJleHAiOjE1MTExODMyODksImlhdCI6MTUxMTE4MTQ4OSwianRpIjoiZWNkMTAzOTktZjM5YS00YjVhLTliZDUtYWViMjQ5MzBiMjYwIiwiY2xpZW50X2lkIjoicmFkYXJfcmVzdGFwaSJ9.mf9V8eHRRBrcoquEYpHL-mY7EICg2cWjYxK-_zaPiqFC38FSHFEouPWqP5dLpLyfjdVSxbdXw8JzSuUlpKif346Qmgq_HpI3hdiurqAiomjjrTiY4MWI6ukeGqAXvBFIo4aHjcUCh1EmUwXkGKRG6DDLK63nK98jyhAJxudW-j-eCBhw02QZUC47J53wCKkGamn9YaSMT2EDajM3YxpVV9-HG-klV8rY9zLXwVbX-G-BYBTSqOdyWZdvDJ5UstqOjFqo7lEQVIDK3lxvzwVBshN599X1PYbENX3oiu36AWC85kwxE3LVunDb7SuTPg1zDU0i5HKyCJHPDxhfvVx9S3ItdAf64Ixv2ytA90isHuWpBcYtLA4YUTap58Jgk4vKfUWeaXXiuzxGCdaEd0GohvMKr7a9Wjjlk9i4h2rkRgwt5DWyyxZqefNvUZMrFw81nLIg8xKQeat6Moh4lnBTTRvbwT1Rt4EQlj-ASrhXjqU6yPC7pxunUHW8TKmoKfuwGne3zEGPBHqlA8Cubm7MZQ47G0EnfMY8sl3NOBmDXQmRZfQkmEg0-POnmOurP7y5ZRBeJJmNuye1c1gwQ8hmSBz8s0Nef7dVg-jBvVwQSr4mugKQM7DR9AuFWVO8_VL0XSoeTBmNnGxQCy-WuWeSkq7T-V7Ig6axF4IOdbwD-sE",
    "token_type": "bearer",
    "expires_in": 1799,
    "scope": "SUBJECT.READ PROJECT.READ SOURCE.READ DEVICETYPE.READ",
    "sub": "radar_restapi",
    "sources": [],
    "iss": "ManagementPortal",
    "iat": 1511181489,
    "jti": "ecd10399-f39a-4b5a-9bd5-aeb24930b260"
}

You can parse this JSON response to get the access token. Then use this token in the header with each request like -

...

Authorization: Bearer <your_access_token>

And with Body as -

{

  "sourceTypeCatalogVersion": "<your_version>",
  "sourceTypeModel": "<your_model>",
  "sourceTypeProducer": "<your_model>"
}

To get these values, you will need to log into the Management Portal as a System Admin and create a new DeviceType for your device or App and take the values from there. The values should be identical. Meta-data is optional and can include any key and value pairs.

...

  • Note that these values have been changed to Source instead of Device in the above screenshot. This request above will return a response with information on the created source, e.g.:
{
  "id" : 1051,
  "sourceTypeId" : 2,
  "sourceTypeProducer" : "THINC-IT App",
  "sourceTypeModel" : "App",
  "sourceTypeCatalogVersion" : "v1",
  "expectedSourceName" : null,
  "sourceId" : "b1296d84-b26b-47f3-be0b-60ebd3405a66",
  "sourceName" : "App-b1296d84",
  "assigned" : true,
  "attributes" : { }
}

The last step is to obtain a new access token that has the source information included since the old token does not contain the new source. This can be done easily by simply following the Step 1 again using the refresh token obtained from the previous access token + refresh tokenresponse. Now you’re all set to start sending data!

...

The request above will return a response with all the versions in an array like this -

[1,2,3]

You need to take the largest value because this is the latest version of the schema for both the key and value.

...

This will return the full information about the schema. A sample response is shown below -

{
    "subject": "android_phone_battery_level-key",
    "version": 3,
    "id": 5,
    "schema": "{\"type\":\"record\",\"name\":\"ObservationKey\",\"namespace\":\"org.radarcns.kafka\",\"doc\":\"Key of an observation.\",\"fields\":[{\"name\":\"projectId\",\"type\":[\"null\",{\"type\":\"string\",\"avro.java.string\":\"String\"}],\"doc\":\"Project identifier. Null if unknown or the user is not enrolled in a project.\",\"default\":null},{\"name\":\"userId\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"},\"doc\":\"User Identifier created during the enrolment.\"},{\"name\":\"sourceId\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"},\"doc\":\"Unique identifier associated with the source.\"}]}"
}

Note that you can also make a GET request to get the latest version like -

...

Next step is to add a body to each request that comprises of the Schema Id of key and value and The Data you want to send in key: value pairs. The Structure of the body will look something like -

{
  "key_schema_id": <your_key_schema_id>,
  "value_schema_id": <your_value_schema_id>,
  "records": [
     {
        "key": {
"projectId": {"string": "project-name"},
"sourceId": "sourceid",
"userId": "subjectid"
}, "value": {
"c": "d",
"e": "f"
} } ] }

Substitute the schema IDs for key and value you found out in the previous step. Note that the key and value of the record should be in the same format as the schema or else you will get an error code.

...

POST <baseUrl>/kafka/topics/<your_topic_name> Content-Type: application/vnd.kafka.avro.v2+json Accept: application/vnd.kafka.v2+json 

Substitute the topic_name with the desired topic and which corresponds to the schemas in the request body. Thats it, you should now be able to send data into kafka topics. If the POST is successful you will receive a 200 response. If not, then there is probably something wrong with the body or schemas.

...

If you are using the client_credentials grant type then you can use Java library oauth-client-util which is available at bintray. For use in gradle, add this -

...
repositories {
    mavenCentral()
    maven { url 'https://dl.bintray.com/radar-cns/org.radarcns' }
}
dependencies {
...
    compile group: 'org.radarcns', name: 'oauth-client-util', version: 0.2.1
...
}
...

To see how how to use it see its implementation in source code of Redcap Integration App.

If you are using the refresh token grant type, then the libraries for QR code and OAuth2 available at QR code library and OAuth2 library maybe useful. To include these, add the following your build.gradle file -

...
repositories {
    jcenter()
    maven { url  'http://dl.bintray.com/radar-cns/org.radarcns' }
    ...
}

dependencies {
    ...
    compile 'org.radarcns:radar-android-login-oauth2:0.3'
    compile 'org.radarcns:radar-android-login-qr:0.3'
    ...
}
...

On information about implementation, take a look at the source code of radar-prmt-android app