当前位置:网站首页>[AGC] build service 3- authentication service example
[AGC] build service 3- authentication service example
2022-06-30 10:12:00 【Huawei Developer Forum】
Preface : Last time I brought you AGC In the field of App Linking Learning from . This time we will continue to deepen our study AGC Knowledge about . Before the article begins , Give the reader a brief introduction AGC, In case the first time readers don't understand . So-called AGC Namely AppGallery Connect For short , Create ideas for users' applications 、 Development 、 distribution 、 operating 、 Provide one-stop service in all links of operation , Put it in a more general way , It is to provide comprehensive services for users to operate applications on the shelf in Huawei application market .
All of the AGC Relevant knowledge is divided into two categories , One major category is related to on the shelf , This can refer to the link :https://developer.huawei.com/consumer/cn/doc/distribution/app/agc-help-overview-0000001100246618. It provides application testing 、 Application of release 、 Application management 、 Application maintenance and other application market related content . Another kind of help for developers Kit, This can refer to the link :https://developer.huawei.com/consumer/cn/doc/development/AppGallery-connect-Guides/agc-introduction-0000001057492641. It provides things like cloud storage 、A/B test 、 Quality analysis 、 Huawei cloud, etc Kit, Provide additional help to developers , Assist developers to better complete the application on the shelf 、 Improve application quality 、 Increase user stickiness, etc .
because AGC There's too much of it , So every time we study, we try to talk about one of them , To be more specific . This time, let's learn the function of the authentication service of the build service . This function can quickly build a safe and reliable user authentication system for applications , You only need to access the relevant capabilities of the authentication service in the application , You don't need to care about the facilities and Implementation on the cloud side . Certification services provide SDK And back end services , Built in support for multiple authentication methods , Provides a powerful management console , It can easily complete the development and management of user authentication . Certification services SDK Support multiple platforms and languages , No matter what type of terminal the user uses , Can get a unified login experience and user identity . Certification services act as Serverless One kind of service can be compared with others Serverless Service auto adaptation , Users can be protected by simple rule definitions Serverless Data security in services .
The main functions of the authentication service :1、 Mobile phone accounts , Authenticate users by their mobile phone numbers , Users can use their mobile phone number and password or mobile phone number and verification code to log in to the application . The authentication service provides registration based on mobile phone number 、 Sign in 、 Password change 、 Password reset 、 Verify SMS push capabilities and interfaces .2、 Email account number , Authenticate users by email address , Users can use email address and password or email address and verification code to log in to the application . The authentication service provides email address based registration 、 Sign in 、 Password change 、 Password reset 、 Verify e-mail push capabilities and interfaces .3、 Third party accounts , Identity authentication for users through third-party authentication services . Users can use a third-party account to log in to the application .4、 Own account number , If you have built your own authentication system , You can connect your own account to make the authentication system you have built work with the authentication service , To achieve the following purposes . Let the authentication service provide authentication methods that your own authentication system does not have ; Allow users in your own authentication system to access others in a secure way Serverless service ( For example, cloud database 、 Cloud storage, etc ).5、 Anonymous account supports the visitor access mode of the application . The authentication service can assign a user ID to your visitors , Enable you to identify different tourists and provide them with differentiated services , And give your visitors safe access to other Serverless service . Tourists can be transformed into official users by associating with other authentication methods , And keep its original user ID unchanged , To keep its business consistent .
How authentication services work , As shown in the figure ,
Implementation process of authentication service .1、 Enable authentication mode , Enable the authentication methods you want to support in the authentication services console , And provide necessary configuration information according to the interface guidance . For third-party account authentication , The application identification and secret key applied in the third-party authentication system shall be provided .2、 Implement the login interface process on the application client , Implement the interface flow required for user login in the application client code :1) For mobile phone account and email account authentication , Please input the account information 、 Password or verification code information interface process , And realize registration 、 Sign in 、 Password change 、 Password reset 、 Verification code push and other processes .2) For third-party account authentication , The login interface process shall be implemented according to the requirements of the third-party authentication system .3) For anonymous account authentication , You need to help or guide visitors to complete anonymous login .4) For self owned account authentication , You can keep your original login experience , And add the authentication service requirements in the process Token Generation and transmission of .3、 End side integrated authentication service SDK, Integrate the authentication service in the end-to-end code of the application SDK, And pass the certification service SDK Submit authentication credentials 、 Receive the certification results .
Then follow the steps of the author to complete a simple authentication service . Because this is just for demonstration , So part of the content has been simplified . Authentication services can also support other platforms , Readers can explore for themselves .
1、 Integrate SDK
1) stay AGC Select the application that needs to enable authentication service in my project of the website , Click on the building -> Certification services , Enter the authentication service page , Activate service now , Click on “ Phone number ” The line where the authentication method is located " Enable ". My side is already open .

2) Sign in AGC Website , Click my project , Under the application column of project settings , Download profile "agconnect-services.json". Copy the configuration file to the application level root directory .


3) add to AGC plug-in unit , stay Android Studio Project level build.gradle Add... To the file maven Warehouse address and HUAWEI agc plug-in unit .

4) open Android Studio Application level build.gradle file , Add add agcp Plug in configuration and agc-auth Compile dependencies .


5) Click... On the interface "Sync Now" Link sync completed configuration .
2、 Interface design
1) stay Android Studio Create a layout page in the project , Refer to the following figure UI Design , Have the ability to input the country code 、 Input box for mobile phone number and verification code, and button for obtaining verification code and login .

Xml Layout code :
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".Activity.LoginActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome to AGC usecase" android:textSize="24dp" android:textAlignment="center" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.2" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.35"> <EditText android:id="@+id/et_countryCode" android:layout_width="60dp" android:layout_height="40dp" android:layout_marginRight="10dp" android:hint=" Country code " android:layout_marginLeft="20dp" android:inputType="number" /> <EditText android:id="@+id/et_phoneNumber" android:layout_width="200dp" android:layout_height="40dp" android:layout_marginRight="20dp" android:hint=" Please enter your mobile number " android:inputType="number"/> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.45"> <EditText android:id="@+id/et_verifyCode" android:layout_width="170dp" android:layout_height="match_parent" android:layout_marginLeft="20dp" android:hint=" Please enter the verification code " android:inputType="number" /> <Button android:id="@+id/bt_obtain" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:layout_marginLeft="20dp" android:textSize="15sp" android:text=" Verification Code " /> </LinearLayout> <LinearLayout android:layout_width="200dp" android:layout_height="45dp" android:gravity="center_horizontal" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.7"> <Button android:id="@+id/bt_phoneLogin" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" android:text=" Mobile number login " android:textSize="18sp" /> </LinearLayout></androidx.constraintlayout.widget.ConstraintLayout>
3、 Certification services sdk Access code implementation
1) stay EditText Enter the country code and mobile phone number respectively , Click the verification code button to call requestVerifyCode Method to get the verification code ,SDK Request to send the authentication code to the authentication service server , Input the received verification code into the verification code EditText in .
// Send verification code method public void sendVerifyCode() { VerifyCodeSettings settings = VerifyCodeSettings.newBuilder() .action(VerifyCodeSettings.ACTION_REGISTER_LOGIN) .sendInterval(30) .locale(Locale.SIMPLIFIED_CHINESE) .build(); String countryCode = et_countryCode.getText().toString().trim(); String phoneNumber = et_phoneNumber.getText().toString().trim(); if (notEmptyString(countryCode) && notEmptyString(phoneNumber)) { Task<VerifyCodeResult> task = PhoneAuthProvider.requestVerifyCode(countryCode, phoneNumber, settings); task.addOnSuccessListener(TaskExecutors.uiThread(), new OnSuccessListener<VerifyCodeResult>() { @Override public void onSuccess(VerifyCodeResult verifyCodeResult) { Toast.makeText(LoginActivity.this, " Verification code has been sent .", Toast.LENGTH_SHORT).show(); } }).addOnFailureListener(TaskExecutors.uiThread(), new OnFailureListener() { @Override public void onFailure(Exception e) { Toast.makeText(LoginActivity.this, " Sending verification code failed ." + e, Toast.LENGTH_SHORT).show(); Log.e(TAG, "requestVerifyCode fail:" + e); } }); } else { Toast.makeText(LoginActivity.this, " Please enter the phone number and country code .", Toast.LENGTH_SHORT).show(); }}
2) Click the mobile number login button , Use the country code 、 The mobile phone number and the received verification code construct the credentials required for the associated account .
call AGConnectAuth.signIn Use generated credential The certificate is used to authenticate the mobile phone number , Print mobile phone users uid To... Below the button TextView.
// Phone number login method public void phoneLogin(){ String countryCode = et_countryCode.getText().toString().trim(); String phoneNumber = et_phoneNumber.getText().toString().trim(); String verifyCode = et_verifyCode.getText().toString().trim(); // Login logic AGConnectAuthCredential credential = PhoneAuthProvider.credentialWithVerifyCode( countryCode, phoneNumber, null, // password, can be null verifyCode); AGConnectAuth.getInstance().signIn(credential) .addOnSuccessListener(new OnSuccessListener<SignInResult>() { @Override public void onSuccess(SignInResult signInResult) { // Get login information String uid = signInResult.getUser().getUid(); String phoneNumber = signInResult.getUser().getPhone(); redirect(uid,phoneNumber); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(Exception e) { Toast.makeText(LoginActivity.this, " Login failed ." +e.getMessage(), Toast.LENGTH_SHORT).show(); Log.e(TAG, "Login error, error:" + e.getMessage()); } });}3) Judge string Not empty method
// Judge string Not empty method public Boolean notEmptyString(String string){ if (string == null || "".equals(string)){ return false; }else { return true; }}4、 Package test
1) function Android Studio Project generation APK package , Install... In the test phone APK package .
2) Enter the country code and mobile number in the interface , Click the verification code button to obtain the verification code .

3) After obtaining the verification code, enter the verification code in the verification code column , Click the login button to log in with your mobile number . I will jump to the main interface after logging in .

above , This time's content sharing , thank you !
For more details , Please see the :
Huawei official website :
https://developer.huawei.com/consumer/cn/forum/topic/0203912789884890322?fid=0101271690375130218?ha_source=zzh
边栏推荐
- G code explanation | list of the most important G code commands
- GNN动手实践(二):复现图注意力网络GAT
- Slf4j: failed to load class "org.slf4j.impl.staticloggerbinder"
- 开源了!文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开
- 乡村振兴公益基金启动暨古茶树非遗保护公益行发布
- Hospital integration platform super fusion infrastructure transformation scheme
- SolidWorks质量特性详解(惯性张量、转动惯量、惯性主轴)
- Small program development journey
- ‘Failed to fetch current robot state‘ when using the ‘plan_kinematic_path‘ service #868
- Practice of super integration and transformation of core production business of public funds
猜你喜欢

MIT-6874-Deep Learning in the Life Sciences Week4

CRF (conditional random field) learning summary

Shenhe thermomagnetic: Super fusion dual active cluster solution for MES system

6.Redis新数据类型

机械臂速成小指南(五):末端执行器

【JVM】CMS简述

NLopt--非线性优化--原理介绍及使用方法

7.手机登陆功能开发
![[JVM] G1 garbage collector](/img/fc/ea1f8cee0f207e4a5c804f88f2871c.png)
[JVM] G1 garbage collector

SolidWorks质量特性详解(惯性张量、转动惯量、惯性主轴)
随机推荐
ModuleNotFoundError: No module named ‘_swigfaiss‘
Based on svelte3 X desktop UI component library svelte UI
著名画家史国良《丰收时节》数字藏品上线长城数艺
MIT-6874-Deep Learning in the Life Sciences Week5
What makes flutter special
Some domestic image sources
Eight sorts (II)
How can we have high performance and simple agility in the enterprise cloud on oracle?
浏览器复制的网址粘贴到文档是超链接
LVS load balancing
【JVM】CMS简述
《锦绣中华》中老年公益文旅游-走进佛山敬老院
Detailed explanation of SolidWorks mass characteristics (inertia tensor, moment of inertia, inertia spindle)
Description of event object
9.缓存优化
UAV project tracking record 83 -- PCB diagram completion
OSError: [Errno 28] No space left on device
train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
About the split and join operations of strings
Shell script functions