English
English
简体中文
Contact Us
Register
Log In
layoutIndex

QR Code-Based Login Authorization

Last Updated on : 2021-11-30 07:54:07download

The QR code login authorization feature allows your app to scan an authorization QR code and enables multiple devices to log in to the app with the same account. The devices can be central control devices, TV sets, or tablets.

Process

In the following process, the app on the central control device must be included in the allowlist. Otherwise, an error message will be returned. For example, if the Tuya Smart app is used to scan the QR code of the SDK that is created on the Tuya IoT Platform and the app is not included in the allowlist, an error message is returned and the session expires.

The following block diagram shows the process of QR code-based login authorization.

QR Code-Based Login Authorization

The following table describes the steps in the process. Five API methods are used in this topic.

No. Purpose Description API method
1 Get the token The device requests to get the token for authorization. -
2 Generate a QR code Use the returned token to generate a QR code in a specific format.
  • Format: tuyaSmart--qrLogin?token=xxxxxxx
  • Example: tuyaSmart--qrLogin?token=AZc72de000-ec00-4000-9e51-b610fc300000.
  • Usage: display the generated QR code on the device screen.
    QR Code-Based Login Authorization
-
3 Get the login status Poll the server to get the authorization status. If the authorization is successful, the user information is returned and users are navigated to the app homepage for subsequent operations. QRCodeLogin
4 Scan the QR code. The app is used to scan and parse the QR code on the device and authorize the device. -
5 Authorize login Send the parsed QR code to the cloud to complete the authorization. loginByQRcode

Parse the QR code

- (void)userInfo:(NSDictionary *)codeInfo success:(nullable TYSuccessID)success failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
codeInfo Scans the QR code.
success The success callback.
failure The failure callback.

Examples

NSDictionary *codeInfo = @{"token": @"****", @"Other information": @""}; // The QR code information.

[[TuyaSmartUser sharedInstance] userInfo:codeInfo success:success failure:failure];

Authorize login

- (void)loginByQRcode:(NSDictionary *)codeInfo success:(nullable TYSuccessID)success failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
codeInfo The information about the QR code.
success The success callback.
failure The failure callback.

Examples

NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:codeInfo];
[dic setValue:[NSString stringWithFormat:@"Current home ID"] forKey:@"homeId"];
[[TuyaSmartUser sharedInstance] loginByQRcode:dic success:success failure:failure];