QR Code Authorization Login - Tuya Smart - App Development

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

QR Code Authorization Login

Android App SDK > User Management

Version: 20201230

Online Version
Contents

Contents

1 Flow description 2
1.1 Get token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Generate QR code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Get login status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Scan QR code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Interface description 5
2.1 Get token interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Get login status interface . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Authorization interface . . . . . . . . . . . . . . . . . . . . . . . . . 6

i
Contents

Note: The app in the following process and the accounting system of the central
control device need to be associated to be used, otherwise, an error will be
reported.

For example, if you use the Tuya Smart app to scan the QR code of your SDK
created by the IoT platform, an error will be reported and the session will be
invalid.

1/7
1 FLOW DESCRIPTION

1 Flow description

The QR code authorization login function is suitable for APP scanning code to au-
thorize another device to log in to the same account. The device can be a central
control device, TV, Pad, etc. The complete authorization process is as follows:

Explanation of the key steps marked in the figure:

2/7
1 FLOW DESCRIPTION

1.1 Get token

The device requests the interface to obtain the token used in the authorization pro-
cess, the interface is getQRCodeToken

1.2 Generate QR code

Use the obtained token to generate a QR code in a specific format:

The format is: tuyaSmart--qrLogin?token=xxxxxxx

Example:

tuyaSmart--qrLogin?token=AZc72de000-ec00-4000-9e51-b610fc300000

Generate QR code

Display the QR code generated from the above string on the screen of the device;

1.3 Get login status

Obtain whether the authorization is successful from the server. If the authorization
is successful, the user information will be returned, jump to the application home
page, and enter the subsequent operation.

3/7
1 FLOW DESCRIPTION

The interface is: QRCodeLogin

1.4 Scan QR code

The app scans the QR code on the device, resolves the token in the QR code, and
performs the authorization operation

1.5 Authorization

Send the parsed QR code to the Server to complete the authorization action.

The authorization interface is QRcodeAuth

4/7
2 INTERFACE DESCRIPTION

2 Interface description

2.1 Get token interface

Used to obtain the token

Declaration

1 void getQRCodeToken ( String countryCode , IGetQRCodeTokenCallback call


2 back);

Parameters

Parameters Description

countryCode country code, for example: 86

callback callback

Example

1 TuyaHomeSdk . getUserInstance (). getQRCodeToken ("86", new IGetQRCodeTok


2 enCallback () {
3 @Override
4 public void onSuccess ( String token ) {
5 }
6 @Override
7 public void onError ( String code , String error ) {
8 }
9 });

2.2 Get login status interface

Declaration

5/7
2 INTERFACE DESCRIPTION

1 void QRCodeLogin ( String countryCode , String token , ILoginCallback ca


2 llback );

Parameters

Parameters Description

countryCode country code, for example: 86

token token

callback callback

Code sample

1 TuyaHomeSdk . getUserInstance (). QRCodeLogin ("86", "xxxx", new ILoginCa


2 llback () {
3 @Override
4 public void onSuccess (User user) {
5 if (user != null && ! TextUtils . isEmpty (user. getSid ())){
6 TuyaHomeSdk . getUserInstance (). loginSuccess (user);
7 // get homeId
8 Object homeId = user. getExtras ().get(" homeId ");
9 gotoHomePage ();
10 }
11 }
12 @Override
13 public void onError ( String code , String error ) {
14 }
15 });

2.3 Authorization interface

Declaration

1 void QRcodeAuth ( String countryCode , long homeId , String token , IBool


2 eanCallback callback );

6/7
2 INTERFACE DESCRIPTION

Parameters

Parameters Description

countryCode country code, for example: 86

homeId home id. Please refer to the Home


Management chapters

token token

callback callback

Example

1 TuyaHomeSdk . getUserInstance (). QRcodeAuth ("86", mHomeId , getActivityT


2 oken () , new IBooleanCallback () {
3 @Override
4 public void onSuccess () {
5 }
6 @Override
7 public void onError ( String code , String error ) {
8 }
9 });

7/7

You might also like