Skip to main content

Profile

Manage a Sahha user profile


Authenticate

The Sahha SDK must be authenticated in order to connect to the Sahha API. Do this once per user profile. Once a profile is authenticated, the SDK will take care of automatically issuing and refreshing API tokens.

You can authenticate a profile in 2 ways - via the API or SDK.


Option A) Authenticate via API

You can authenticate a user profile via the API and then pass the Profile Token to the SDK.

View the API docs: API - Authenticate User Profile

Step 1) Use your accountToken and externalId to authenticate a user profile via the profile/register endpoint.

REQUEST
// POST "/oauth/profile/register"
// AUTHORIZATION HEADER "Account MY_ACCOUNT_TOKEN"

// BODY
{
"externalId": "MY_EXTERNAL_ID"
}

You will receive a profileToken and refreshToken in the API response.

RESPONSE
// POST "/oauth/profile/register"
// AUTHORIZATION HEADER "Account MY_ACCOUNT_TOKEN"

// BODY
{
"profileToken": "PROFILE_TOKEN",
"expiresIn": "86400",
"tokenType": "Profile",
"refreshToken": "REFRESH_TOKEN"
}

Step 2) Pass the profileToken and refreshToken you generated via the API to the SDK.

MyApp.swift
Sahha.authenticate(profileToken: "PROFILE_TOKEN", refreshToken: "REFRESH_TOKEN") { error, success in
if let error = error {
print(error)
} else if success {
print("You are now authenticated")
}
}

Option B) Authenticate via SDK

You will need your App ID and App Secret to authenticate user profiles with an External ID.

MyApp.swift
Sahha.authenticate(appId: "APP_ID", appSecret: "APP_SECRET", externalId: "EXTERNAL_ID") { error, success in
if let error = error {
print(error)
} else if success {
print("You are now authenticated")
}
}

Using Your App ID and App Secret

If you choose to authenticate a user profile via the SDK, you will need to user your App ID and App Secret.

Finding your App ID and App Secret

Your appId and appSecret are available in the Sahha dashboard.

Login to the Sahha Dashboard

These values are separate from your clientId and clientSecret and should only be used to authenticate a profile via the SDK.

Using your App ID and App Secret

DO NOT store your app ID and App Secret in your app code. Your account could be harmed if any 3rd party gains access to these two values.

We recommend storing and accessing these values from your server on app launch.


Using Your External ID

You will need to provide your own unique External ID to authenticate a user profile.

Choosing your External ID

An External ID can be any string you choose to identify a user profile within your organization. This ID must be unique for each of your users. This ID has a limit of 100 characters.

We suggest using an anonymous UUID e.g. 123e4567-e89b-12d3-a456-426614174000

If your user changes devices, make sure to use the same External ID to identify them on the new device.

User Privacy

Sahha does not collect personally identifiable information from users due to privacy and security.

DO NOT use an External ID that could be used to personally identify a user.

For example, do not use emails or usernames for External ID:


Deauthenticate

If you would like to change authenticated users, first deauthenticate the current user before authenticating a new user.

The SDK will take care of switching user data and automatically issuing and refreshing API tokens.

MyApp.swift
Sahha.deauthenticate { error, success in
if let error = error {
print(error)
} else if success {
print("You are now deauthenticated")
}
}

Check Authentication

You can easily check if a profile is already authenticated via the SDK.

MyApp.swift
if Sahha.isAuthenticated {
print("Profile is ready")
} else {
print("You must authenticate your profile")
}

Demographic

Each authenticated profile includes an optional demographic which can be used to increase the accuracy of analyzation. This data is not collected automatically. Your app can choose to GET or POST this demographic via the Sahha API.

All values are optional

String values are case insensitive (for example: 'us' and 'US' are equal and valid).

age : Int

Age must be a valid Int between 1 - 99.

gender : String

Gender must be a valid String from this list:

  • 'male'
  • 'female'
  • 'gender diverse'

country : String

Country must be a valid 2 character ISO String from this list:

ISO Country Codes

birthCountry : String

Birth Country must be a valid 2 character ISO String from this list:

ISO Country Codes

ethnicity : String

Any String value.

occupation : String

Any String value.

industry : String

Any String value.

incomeRange : String

Any String value.

education : String

Any String value.

relationship : String

Any String value.

locale : String

Any String value.

livingArrangement : String

Any String value.

birthDate : String

Birth Date must be a String in the format 'YYYY-MM-DD'. For example, '1990-05-20'.


MODEL

You can GET or POST demographic info via the API using this model.

MyApp.swift
// All values are optional

public struct SahhaDemographic: Codable {
public var age: Int?
public var gender: String? // "male", "female", "gender diverse"
public var country: String? // ISO 2 character code, i.e. "us", "uk", "au", etc.
public var birthCountry: String? // ISO 2 character code, i.e. "us", "uk", "au", etc.
public var ethnicity: String? // any string
public var occupation: String? // any string
public var industry: String? // any string
public var incomeRange: String? // any string
public var education: String? // any string
public var relationship: String? // any string
public var locale: String? // any string
public var livingArrangement: String? // any string
public var birthDate: String? // must be in format "YYYY-MM-DD", i.e. "1990-05-20"
}

POST

An example POST of demographic info via the SDK.

MyApp.swift
let demographic = SahhaDemographic(
age: 32,
gender: "Female",
country: "NZ",
birthCountry: "UK",
birthDate: "1990-05-20"
)

Sahha.postDemographic(demographic) { error, success in
if let error = error {
print(error)
}
print(success)
}

GET

An example GET of demographic info via the SDK.

MyApp.swift
Sahha.getDemographic() { error, demographic in
if let error = error {
print(error)
}
if let demographic = demographic {
print(demographic)
}
}