Customer authentication

Register Customer account


Register a new Customer with email, password and optional data.

This method requires the SNRRegisterClientContext object with a Customer’s email, password and optional data. Omitted fields are not modified.

Depending of backend configuration, the account may require activation. For details, see registering new customer.

Do NOT allow to sign in again (or sign up) when a customer is already signed in. Sign the customer out first.

Do not create multiple instances nor call this method multiple times before execution. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

SNRClientAgreements.h
SNRClientRegisterAccountContext.h

Method Name

Client.registerAccount(context:success:failure:)

Declaration

func registerAccount(context: ClientRegisterAccountContext, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void

Parameters

Parameter Type Mandatory Default Description
context SNRClientRegisterAccountContext yes - Object with the Customer’s email, password, and other optional data
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let agreements: ClientAgreements = ClientAgreements()
agreements.email = true
agreements.sms = true
agreements.push = true
agreements.bluetooth = true
agreements.rfid = true
agreements.wifi = true
let email: String = "YOUR_EMAIL"
let password: String = "YOUR_PASSWORD"
let context: ClientRegisterAccountContext = ClientRegisterAccountContext(email: email, password: password)
context.firstName = "FIRST_NAME"
context.lastName = "LAST_NAME"
context.customId = "CUSTOM_ID"
context.sex = .male
context.phone = "123-456-789"
context.company = "Synerise"
context.address = "Lubostroń 1"
context.city = "Kraków"
context.province = "Małopolskie"
context.zipCode = "30-383"
context.countryCode = "+48"
context.agreements = agreements
context.attributes = ["attribute1": "value1", "attribute2": "value2"]
context.tags = ["tag1", "tag2" "tag3"]
Client.registerAccount(context: context, success: { (success) in
	// success
}, failure: { (error) in
	// failure
})

Confirm Customer account


Confirm a Client account with the confirmation token.

The Method returns the HTTP 400 status code if the account is already confirmed or 404 if the account does not exist. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

Method Name

Client.confirmAccount(token:success:failure:)

Declaration

func confirmAccount(token: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
token String yes - Confirmation token
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let token: String = "TOKEN"
Client.confirmAccount(token: token, success: { (success) in
	// success
}, failure: { (error) in
	// failure
})

Activate Customer account


Activate a Customer account with email. This method requires the Client’s email. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

Method Name

Client.activateAccount(email:success:failure:)

Declaration

func activateAccount(email: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Return Value

There is no return value.

Example

let email: String = "EMAIL"
Client.activateAccount(email: email, success: { (success) in
	// success   
}) { (error) in
	// failure 
}

Sign in a Customer


Sign in a customer in order to obtain the JWT token, which can be used in subsequent requests.

The token is valid for 1 hour (unless configured otherwise in Synerise) and the SDK will refresh the token before each call if it is expiring soon (but still valid).

The method requires valid and non-null email and password.

Do NOT allow to sign in again (or sign up) when a customer is already signed in. Sign the customer out first.

Do not create multiple instances nor call this method multiple times before execution. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

Method Name

Client.signIn(email:password:success:failure:)

Declaration

func signIn(email: String, password: String, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void

Parameters

Parameter Type Mandatory Default Description
email String yes - Customer’s email
password String yes - Customer’s password
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let email: String = "EMAIL"
let password: String = "PASSWORD"
Client.signIn(email: email, password: password, success: { (success) in
	// success
}, failure: { (error) in
	// failure
})

Authenticate Customer by OAuth


Use this method to sign in with an OAuth authorization token.

The HTTP 401 status code is returned if the provided access token and/or API Key is invalid. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

SNRClientAgreements.h
SNRClientOAuthContext.h

Method Name

Client.authenticateByOAuth(accessToken:authID:success:failure:)

Declaration

func authenticateByOAuth(accessToken: String, authID: String?, context: ClientOAuthContext?, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
accessToken String yes - OAuth Access Token
authID String no - Custom identity for authorization
context SNRClientOAuthContext no - Object with authorization agreements and optional attributes
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let agreements: ClientAgreements = ClientAgreements()
agreements.email = true
agreements.sms = true
agreements.push = true
agreements.bluetooth = true
agreements.rfid = true
agreements.wifi = true
let context: ClientOAuthContext = ClientOAuthContext()
context.agreements = agreements
context.attributes = ["attribute1": "value1", "attribute2": "value2"]
let accessToken: String = "ACCESS_TOKEN"
let authID: String = "AUTH_ID"
Client.authenticateByOAuth(accessToken: accessToken, authID: authID, context: context, success: { (success) in
	// success
}) { (error) in
	// failure   
}

Authenticate Customer by Facebook with registration


Use this method to sign in with Facebook (for Customers that are not registered yet)

The HTTP 401 status code is returned if the provided Facebook token and/or API Key is invalid.

Declared In

SNRClient.h

SNRClientAgreements.h
SNRClientFacebookAuthenticationContext.h

Method Name

Client.authenticateByFacebook(facebookToken:authID:success:failure:)

Declaration

func authenticateByFacebook(facebookToken: String, authID: String?, context: ClientFacebookAuthenticationContext?, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
facebookToken String yes - Facebook Access Token
authID String no - Custom identity for authorization
context SNRClientFacebookAuthenticationContext no - Object with authorization agreements and optional attributes
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

let agreements: ClientAgreements = ClientAgreements()
agreements.email = true
agreements.sms = true
agreements.push = true
agreements.bluetooth = true
agreements.rfid = true
agreements.wifi = true

let context: ClientFacebookAuthenticationContext = ClientFacebookAuthenticationContext() context.agreements = agreements context.attributes = ["attribute1": "value1", "attribute2": "value2"]

guard let facebookToken = FBSDKAccessToken.current()?.tokenString else { return } let authID: String = "AUTH_ID"

Client.authenticateByFacebook(facebookToken: fa, authID: authID, context: context, success: { (success) in // success }) { (error) in // failure }

Authenticate Customer by Facebook without registration


Use this method to sign in with already registered Facebook account.

The HTTP 401 status code is returned if there is no associated account with the provided facebook token. This method is a global operation and does not require authorization.

Declared In

SNRClient.h

Method Name

Client.authenticateByFacebookIfRegistered(facebookToken:authID:success:failure:)

Declaration

func authenticateByFacebookIfRegistered(facebookToken: String, authID: String?, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
facebookToken String yes - Facebook Access Token
authID String no - Custom identity for authorization
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

guard let facebookToken = FBSDKAccessToken.current()?.tokenString else {
	return
}
let authID: String = "AUTH_ID"
Client.authenticateByFacebookIfRegistered(facebookToken: facebookToken, success: { (success) in
	// success
}, failure: { (error) in
	// failure
})

Authenticate Customer by Sign in with Apple


Use this method to sign in with Apple Sign In.

Declared In

SNRClient.h

SNRClientAgreements.h
SNRClientAppleSignInAuthenticationContext.h

Method Name

Client.authenticateByAppleSignIn(context:authID:success:failure:)

Declaration

func authenticateByAppleSignIn(context: SNRClientAppleSignInAuthenticationContext, authID: String?, success: ((Bool) -> ()), failure: ((Error) -> ())) -> Void) -> Void

Parameters

Parameter Type Mandatory Default Description
context SNRClientAppleSignInAuthenticationContext no - Object with authorization agreements and optional attributes
authID String no - Custom identity for authorization
success Block/Closure no - Block/closure to be executed when the operation finishes successfully
failure Block/Closure no - Block/closure to be executed when the operation finishes unsuccessfully

Return Value

There is no return value.

Example

extension LoginViewController: ASAuthorizationControllerDelegate {
	func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
	    if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
			let agreements: ClientAgreements = ClientAgreements()
			agreements.email = true
			agreements.sms = true
			agreements.push = true
			agreements.bluetooth = true
			agreements.rfid = true
			agreements.wifi = true
			let context: ClientAppleSignInAuthenticationContext = ClientAppleSignInAuthenticationContext(identityToken: appleIdCredential.identityToken!)
			context.agreements = agreements
			context.attributes = ["param": "value"]
			Client.authenticateByAppleSignIn(context: context, authID: authID, success: { (success) in
				// success
			}) { (error) in
				// failure
			}
	    }
	}
}

Check if a Customer is signed in


Check if a Customer is signed in (their token is authorized).

Declared In

SNRClient.h

Method Name

Client.isSignedIn()

Declaration

func isSignedIn() -> Bool

Return Value

true if the customer is signed in, otherwise return false.

Example

let isSignedIn: Bool = Client.isSignedIn()

Sign out Customer


Signing a Customer out clears the Customer’s JWT token.

Declared In

SNRClient.h

Method Name

Client.signOut()

Declaration

func signOut() -> Void

Return Value

There is no return value.

Example

Client.signOut()
😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.