Documentation for an Identity Developer to set up QR code based authentication.
🚧 This project is a work in progress. Please do not use this yet!
-
Start the WSO2 Identity server. If you haven't downloaded yet, please visit https://wso2.com/identity-server/ and download the latest version of the Identity server.
-
Create a service provider/ application in WSO2 IS and configure it following one of the procedures mentioned below.
-
Login to WSO2 IS management console from https://localhost:9443/carbon/ and navigate to the Service Providers tab listed under the Identity section.
-
Click Add to add a new service provider.
-
Provide a name for the Service Provider (ex:- sampleRN-app) and click Register. Now you will be redirected to the Edit Service Provider page.
-
Expand the Inbound Authentication Configuration section and click Configure under the OAuth/OpenID Connect Configuration section.
-
Under Allowed Grant Types uncheck everything except
Code
andRefresh Token
. -
Enter Callback URL(s) as for the following values.
Callback Url:
wso2sample://oauth2
Alternatively if you're running in an emulator, you can use
http://10.0.2.2:8081
as the callback url.
-
Check Allow authentication without the client secret.
-
Click Add button to add the OAuth configurations.
-
Once the configurations are added, you will be redirected to the Service Provider Details page. Here, expand the Inbound Authentication Configuration section and click on the OAuth/OpenID Connect Configuration. Copy the value of
OAuth Client Key
shown here.
-
Login to WSO2 IS management console from https://localhost:9443/carbon/ and navigate to the Service Providers tab listed under the Identity section.
-
Click Add to add a new service provider.
-
Provide a name for the Service Provider (ex:- sample-web-app) and click Register. Now you will be redirected to the Edit Service Provider page.
-
Expand the Inbound Authentication Configuration section and click Configure under the OAuth/OpenID Connect Configuration section.
-
Under Allowed Grant Types uncheck everything except
Code
andRefresh Token
. -
Enter Callback URL(s) as
https://localhost:5000
(or whichever the URL your app is hosted on). -
Check Allow authentication without the client secret.
-
Click Add button to add the OAuth configurations.
-
Once the configurations are added, you will be redirected to the Service Provider Details page. Here, expand the Inbound Authentication Configuration section and click on the OAuth/OpenID Connect Configuration. Copy the value of
OAuth Client Key
shown here.
- Navigate to the
Local and Outbound Authentication Configuration
section of the registered Service Provider.
-
Go to
Advanced Configuration
and set up the authentication flow as below. -
Once the configuration is done, make sure to click the
Update
button to save the changes.
-
Install the dependencies and generate the tar file for
asgardeo-react-native-oidc-sdk
by running the following command inside thelib/
directory.npm pack
-
Add the relevant configurations to the LoginScreen file located at
sample/screen/LoginScreen
folder.-
Replace the value of
clientID
with the value ofOAuth Client Key
orClient ID
which you copied in the previous section of the documentation (configuring the Identity Server).const config = { serverOrigin: 'https://{hostname}:9443', signInRedirectURL: 'http://{hostname}:{port}', clientID: 'ClientID', SignOutURL: "http://{hostname}:{port}" // (Optional) };
Example:
const config = { serverOrigin: 'https://10.0.2.2:9443', signInRedirectURL: 'wso2sample://oauth2', clientID: 'iMc7TiIaIFafkd5hA5xf7kGiAWUa', SignOutURL: "http://10.0.2.2:8081" // (Optional) };
-
-
Install the required dependencies by running the following command inside the
sample/
directory.npm install
This application can be run either in an emulator or an actual device. Some configurations may differ depending on the OS.
-
If the WSO2 IS is hosted in the local machine, you have to change the domain of the endpoints defined in
config
object atscreen/LoginScreen
file to10.0.2.2
. Refer the documentation on emulator-networking. Next change the hostname of Identity server as10.0.2.2
in the<IS_HOME>/repository/conf/deployment.toml
file. -
By default IS uses a self-signed certificate. If you ended up in SSL issues and are using the default pack without changing to a CA signed certificate, follow this guide to get rid of SSL issues.
-
Sometimes you may get
SSLHandshakeException
in android application since WSO2 IS is using a self-signed certificate. To fix this exception, you need to add the public certificate of IS to the sample application.i. Create a new keystore with CN as localhost and SAN as
10.0.2.2
.keytool -genkey -alias wso2carbon -keyalg RSA -keystore wso2carbon.jks -keysize 2048 -ext SAN=IP:10.0.2.2
ii. Export the public certificate (ex:
wso2carbon.pem
) to add into the truststore.keytool -exportcert -alias wso2carbon -keystore wso2carbon.jks -rfc -file wso2carbon.pem
iii. Import the certificate in the client-truststore.jks file located in
<IS_HOME>/repository/resources/security/
.keytool -import -alias wso2is -file wso2carbon.pem -keystore client-truststore.jks -storepass wso2carbon
iv. Now copy this public certificate (
wso2carbon.pem
) to theapp/src/main/res/raw
folder.v. Create a new file named
network_security_config.xml
insample/android/app/src/main/res/xml
folder and copy the below content to it. Make sure to replacewso2carbon
with the certificate name you added.<?xml version="1.0" encoding="utf-8"?> <network-security-config> <domain-config cleartextTrafficPermitted="true"> <domain includeSubdomains="true">localhost</domain> <domain includeSubdomains="true">10.0.2.2</domain> <trust-anchors> <certificates src="@raw/wso2carbon"/> </trust-anchors> <domain includeSubdomains="true">192.168.43.29</domain> <base-config cleartextTrafficPermitted="true"/> </domain-config> </network-security-config>
vi. Then add the following config to the
sample/android/app/src/main/AndroidManifest.xml
file underapplication
section.android:networkSecurityConfig="@xml/network_security_config"
Now the
AndroidManifest.xml
file should look like below.<?xml version="1.0" encoding="utf-8"?> <manifest ... > <application android:networkSecurityConfig="@xml/network_security_config" ... > ... </application> </manifest>
-
Create a suitable Android virtual device using the Android virtual device manager (AVD Manager) and launch it.
-
Build and deploy the apps by running the following command at the root directory.
react-native run-android
-
Enable Debugging over USB and plug in your device via USB.
-
Build and deploy the apps by running the following command at the root directory.
react-native run-android
If you're running in a development or debugging mode, start the Metro by running the following command.
react-native start
- Install the auth-react library from the npm registry.
npm install --save @asgardeo/auth-react
- Update configuration file
src/config.json
with your registered app details.
Note: You will only have to paste in the clientID
(OAuth Client Key) generated for the application you registered.
{
"clientID": "uq3OFqKaJeU5BFjCWIaBkz6Vv4ca",
"serverOrigin": "https://192.168.1.4:9443",
"signInRedirectURL": "https://localhost:5000",
"signOutRedirectURL": "https://localhost:5000"
}
- Build and deploy the apps by running the following command at the root directory.
npm install && npm start
Navigate to https://localhost:5000
(or whichever the URL you have hosted the sample app).
Node.js
(version 10 or above)npm
package manager- React Native Environment setup
Please read Contributing to the Code Base for details on our code of conduct, and the process for submitting pull requests to us.
We encourage you to report issues, improvements, and feature requests creating Github Issues.
Important: And please be advised that security issues must be reported to security@wso2com, not as GitHub issues, in order to reach the proper audience. We strongly advise following the WSO2 Security Vulnerability Reporting Guidelines when reporting the security issues.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.