Sensitive Profile Attributes

Sensitive Profile Attributes

This mutation creates user profile attributes using Asymmetric Encryption each partner needs to have its Public and Private Keys 🔑

mutation {
  sensitiveProfileAttributes(
    attributes: "ZnlnY1QImbEse19xxr3tLulEzWxiRQTk4h2D4IYZkzCj+wwKhTlqQfi9PSs5I+BH4h/A2pIFiitweny3bK7dOKF2lkwtNPRKNu/VXWA423sQVdZct1w1pe6MExFhNm7r/y4rseJs+i30gsDC3EMo3tPgbiYB2UXMMKfe34cSb0xP1pnSTPHs+feyzSASojxl7bkoZ+nN9/rwpdPpsZ10ncO4CvYLVTZBiep7y/TC5HSQZCRGfHfAdFzYTYfgdD17gskvwvGUvdRJuFxEEYHZUze+uqBzg36nbQQzCLMzqyFFS0iuYTEvZt01iDprnIdZGAP+nElmc7yJGb+5yXvGdLutWjntACcQUFzqRKaX/RrWoxOg+zHQvIJ78VY51ReL0vRQrOlV4Nh83aBGki395A40tTMHMJpqUm8kDAfu7RoCZlTVWfVo09BrrRUAFnBfrAejSiIwcxIp98qZhyIQtoq8zxBl2JqxrYpgWes/DIo1AguBVN5Lwh+YTU3oL68Wfwh3ULlR6hCAQ9Cf/NsT5bUx9/F8epOY5ExhACZV+/W1qLjJwYx8NH+OKXxzIEXtbS3RAZehlxTMDj2PLqzd5tA1dhE+NR4HTiWSCFbv+mDY8xHtuw/AtRd587gynUVfBHuyNSKl0dFgLGIHydC9zG3K2z6kWbaxeR9OtVU0fTV1ulPf+wE3MeZQUlweBYqtUJP2/JZheNcU+pEfdkJlPMukqKSyRbgBkSM3ZTaXsdrGZF1eZicWiYAj+2cXv2MFZffg6kjZlGovW/PLQSAGgmnJJw7UbTIbMlxNMaZOlOnPwmUWGpsW8+j6O46BtH3fe5HF9ucu3gUpmBLmn9kJJcZ/nB+a/YuW/DUlInWo0SzpO9PJSaXXQmvgu6y5gO044maeFRQA65jlf8f3/gL0bSiEZQUwrzKGilvE7S8pBSkstaELE3HVqVFbB/RnUat/zJWIynu0wWeYxpfeu0l6X3va8/iisSLGJByEnY4SF+FElMICHBxZgTl8j88od+F67aeHY5qtJhbbzIwQqtWxNPAh8aNTjYEYe5RgIFw3YpNvs3v8NOT26iwX/AW7fqtWwq8cq4qzgLHR8BOEFSrrHTrUMh0wIuHJG1OyuK6hbqD0E2YRgmd5KYON8kgeNOpABUTcKblIDYAA4vq032VT0v9AfvILXeMyVcxZNYSrA7XMDoWWYHkjXDTcKF1xsw90IKmUIDKyKOPLwnP15fbnWObw2WZVtRl8md+Wg040iEj68zLEqML1tCHyaPFzBHltPOlS+VhUrgiwmekEy4CLUORxkXqVa1was8l/NHT6zVdpavLcrGHEOHwpO5XeekTSrfJvRg7TGqfePh0252L6IHWTpSDLaGAQIUybWKaOccyla7mehjVybiOUO1FHg2rlrKxu1eqPK71RtDtF9566VbI9INBNNSUeH0yNAjjJSV9AWuRHW9q8KEoYjst6iC/ym6P+/nh0SEZeNxbIPOFqP5DOxmWvw2/4yzzlloyCzfYHqb2nOinUfdJvAO/s+f0wPexmx6NT9Fx84kQEkPIYVEvpNUxpPUSgKq7i492Kj/reX3QXjOMAj/bMO2RTTRLqTlZZW9dfN/fpHDSgKuGHhrDiVkqAstVzMymVnECtuY9//kBUdanfjdbTXR/fN11/H80AwhJmYGX+9VnDFENRp/gWjKqYSa63rel9Agln4rpCWQ0oI3xyIA41sKjzE3s3Y8DbEYKbnhlvSC8dCxxhEjVUIIkupZBXKOY45nFshFGrmWp1rFx1Vxmn3KFTXCSjcFcaaoLirLYvG3KFLMgrI3AbGnfa00twrdQR/t3jZvc="
  ) {
    success
    errors {
      field
      messages
    }
  }
}

Decrypted attributes

Attributes structure should be the same as CustomProfileAttribute

[
      {
        name: "Carbohydrate Metabolism",
        dataType: STRING,
        value: "Slow"
      },
      {
        name: "Gluten Sensitivity",
        dataType: INT,
        value: 1
      },
      {
        name: "Lactose Tolerance",
        dataType: FLOAT,
        value: 1.4
        },
      {
        name: "Fiber Need",
        dataType: BOOLEAN,
        value: true
      }
]

​Generating Keys

In order to encrypt users' profile attributes will need to create a private and public key, this can be achieved using OpenSSL.

# Private key
openssl genrsa -out privkey.pem 2048
# Public key
openssl rsa -in privkey.pem -pubout -out pubkey.pem

You can now share your 🔑 pubkey.pem with Suggestic, this way we can decode users' attributes on or end.

Store securely and do not share your privkey.pem key 🔑

Once the public and private keys are created you can then use them to encode users attributes using JWT RS256

import jwt
# Encoding user attr in partners end
private_key = b"-----BEGIN PRIVATE KEY-----\nMIGEAgEAMBAGByqGSM49AgEGBS..."
public_key = b"-----BEGIN PUBLIC KEY-----\nMHYwEAYHKoZIzj0CAQYFK4EEAC..."
encoded = jwt.encode(
    {"name": "Carbohydrate Metabolism"},
    private_key,
    algorithm="RS256"
)
print(encoded)
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzb21lIjoicGF5bG9hZCJ9.4twFt5NiznN84AWoo1d7KO1T_yoc0Z6XOpOVswacPZg

# Decoding - this happens in Suggestic end
decoded = jwt.decode(encoded, public_key, algorithms=["RS256"])
{'name': 'Carbohydrate Metabolism'}

Last updated