Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 9e8119e

Browse files
authored
Release/1.0.2 (#6)
- Write the README (#5) - Bump version to 1.0.2
2 parents b4f8408 + 1741ebc commit 9e8119e

21 files changed

Lines changed: 433 additions & 11 deletions

README.md

Lines changed: 215 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
Virtusize Auth SDK for Android
1+
# Virtusize Auth SDK for Android
22

33
## Description
44

55
The Virtusize Auth SDK for Android is a closed-source library that handles the SNS authentication process for our [Virtusize Android Integration](https://github.com/virtusize/integration_android).
66

7+
8+
9+
## Requirements
10+
11+
- minSdkVersion >= 21
12+
13+
- compileSdkVersion >= 30
14+
15+
- Setup in AppCompatActivity
16+
17+
18+
719
## Getting Started
820

9-
1. In your root build.gradle file, edit the `repositories` section to include the following:
21+
### 1. Installation
22+
23+
1. In your *root* build.gradle file, edit the `repositories` section to include the following:
1024

1125
```groovy
1226
allprojects {
@@ -18,10 +32,207 @@ allprojects {
1832
}
1933
```
2034

21-
2. In your root build.gradle file, edit the `dependencies` section to include the following:
35+
2. In your *app* build.gradle file, edit the `dependencies` section to include the following:
2236

2337
```groovy
2438
dependencies {
25-
implementation "com.virtusize.android:virtusize_auth_android:1.0.1"
39+
implementation "com.virtusize.android:virtusize_auth_android:1.0.2"
2640
}
2741
```
42+
43+
44+
45+
### 2. Create a Custom URL Scheme for Virtusize SNS Auth
46+
47+
The SNS authentication flow requires opening a Chrome Custom Tab, which will load a web page for the user to login with their SNS account. In order to return the login response from a Chrome Custom Tab to your app, a custom URL scheme must be defined inside the manifest.
48+
49+
Edit your `AndroidManifest.xml` file to include an intent filter and a `<data>` tag for the custom URL scheme.
50+
51+
```xml
52+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
53+
package="com.your-company.your-app">
54+
55+
<activity
56+
android:name="com.virtusize.android.auth.views.VitrusizeAuthActivity"
57+
android:launchMode="singleTask"
58+
android:exported="true">
59+
<intent-filter>
60+
<action android:name="android.intent.action.VIEW" />
61+
62+
<category android:name="android.intent.category.DEFAULT" />
63+
<category android:name="android.intent.category.BROWSABLE" />
64+
65+
<data
66+
android:host="sns-auth"
67+
android:scheme="com.your-company.your-app.virtusize" />
68+
</intent-filter>
69+
</activity>
70+
71+
</manifest>
72+
```
73+
74+
**❗IMPORTANT**
75+
76+
1. The URL host has to be `sns-auth`
77+
2. The URL scheme must begin with your app's package ID (com.your-company.your-app) and **end with .virtusize**
78+
3. The scheme which you define must use all **lowercase** letters
79+
80+
81+
82+
## Enable Virtusize SNS Login for your WebView app
83+
84+
Use either of the following methods to enable Virtusize SNS login
85+
86+
### Method 1: Use the VirtusizeWebView
87+
88+
##### **Step 1: Replace your `WebView` with `VirtusizeWebView`**
89+
90+
To enable users to sign up or log in with the web version of Virtusize integration in your webview, please replace your `WebView` with **`VirtusizeWebView`** in your Kotlin or Java file and XML file to fix and enable SNS login in Virtusize.
91+
92+
- Kotlin/Java
93+
94+
```diff
95+
// Kotlin
96+
- var webView: WebView
97+
+ var webView: VirtusizeWebView
98+
99+
// Java
100+
- WebView webView;
101+
+ VirtusizeWebView webView;
102+
```
103+
104+
and
105+
106+
- XML
107+
108+
```diff
109+
- <WebView
110+
+ <com.virtusize.libsource.VirtusizeWebView
111+
android:id="@+id/webView"
112+
android:layout_width="match_parent"
113+
android:layout_height="match_parent" />
114+
```
115+
116+
##### Step 2: Set the Virtusize SNS auth activity result launcher to `VirtusizeWebView`
117+
118+
- Kotlin
119+
120+
```kotlin
121+
// Register the Virtusize SNS auth activity result launcher
122+
private val virtusizeSNSAuthLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
123+
// Handle the SNS auth result of the VirtusizeAuthActivity by passing the webview and the result to the `VirtusizeAuth.handleVirtusizeSNSAuthResult` function
124+
VirtusizeAuth.handleVirtusizeSNSAuthResult(webView, result.resultCode, result.data)
125+
}
126+
127+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
128+
super.onViewCreated(view, savedInstanceState)
129+
// ... other code
130+
131+
// Set the activity result launcher to the webView
132+
webView.setVirtusizeSNSAuthLauncher(virtusizeSNSAuthLauncher)
133+
}
134+
```
135+
136+
- Java
137+
138+
```java
139+
// Register the Virtusize SNS auth activity result launcher
140+
private ActivityResultLauncher<Intent> mLauncher =
141+
registerForActivityResult(
142+
new ActivityResultContracts.StartActivityForResult(),
143+
(ActivityResultCallback<ActivityResult>) result ->
144+
VirtusizeAuth.INSTANCE.handleVirtusizeSNSAuthResult(webView, result.getResultCode(), result.getData())
145+
);
146+
147+
148+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
149+
super.onViewCreated(view, savedInstanceState)
150+
// ... other code
151+
152+
// Set the activity result launcher to the webView
153+
webView.setVirtusizeSNSAuthLauncher(virtusizeSNSAuthLauncher)
154+
}
155+
```
156+
157+
158+
### or
159+
160+
### Method 2: Use WebView
161+
162+
##### Step 1: Make sure your WebView enables the following settings:
163+
164+
```kotlin
165+
webView.settings.javaScriptEnabled = true
166+
webView.settings.domStorageEnabled = true
167+
webView.settings.databaseEnabled = true
168+
webView.settings.setSupportMultipleWindows(true)
169+
```
170+
171+
##### Step 2: Add the following code
172+
173+
```kotlin
174+
// Register the Virtusize SNS auth activity result launcher
175+
private val virtusizeSNSAuthLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
176+
VirtusizeAuth.handleVirtusizeSNSAuthResult(webView, result.resultCode, result.data)
177+
}
178+
179+
override fun onCreate(savedInstanceState: Bundle?) {
180+
super.onCreate(savedInstanceState)
181+
182+
webView.webViewClient = object : WebViewClient() {
183+
override fun onPageFinished(view: WebView?, url: String?) {
184+
// Enable SNS buttons in Virtusize
185+
webView.evaluateJavascript("javascript:window.virtusizeSNSEnabled = true;", null)
186+
187+
// The rest of your code .....
188+
}
189+
}
190+
191+
webView.webChromeClient = object : WebChromeClient() {
192+
override fun onCreateWindow(
193+
view: WebView,
194+
dialog: Boolean,
195+
userGesture: Boolean,
196+
resultMsg: Message
197+
): Boolean {
198+
// Obtain the popup window link or link title
199+
val message = view.handler.obtainMessage()
200+
view.requestFocusNodeHref(message)
201+
val url = message.data.getString("url")
202+
val title = message.data.getString("title")
203+
if (resultMsg.obj != null && resultMsg.obj is WebView.WebViewTransport && VirtusizeURLCheck.isLinkFromVirtusize(url, title)) {
204+
val popupWebView = WebView(view.context)
205+
popupWebView.settings.javaScriptEnabled = true
206+
popupWebView.webViewClient = object : WebViewClient() {
207+
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
208+
if (VirtusizeURLCheck.isExternalLinkFromVirtusize(url)) {
209+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
210+
try {
211+
context.startActivity(intent)
212+
} finally {
213+
return true
214+
}
215+
}
216+
return VirtusizeAuth.isSNSAuthUrl(context, virtusizeSNSAuthLauncher, url)
217+
}
218+
}
219+
popupWebView.webChromeClient = object : WebChromeClient() {
220+
override fun onCloseWindow(window: WebView) {
221+
webView.removeAllViews()
222+
}
223+
}
224+
val transport = resultMsg.obj as WebView.WebViewTransport
225+
view.addView(popupWebView)
226+
transport.webView = popupWebView
227+
resultMsg.sendToTarget()
228+
return true
229+
}
230+
231+
// The rest of your code .....
232+
233+
return super.onCreateWindow(view, dialog, userGesture, resultMsg)
234+
}
235+
}
236+
}
237+
```
238+
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
91f72416de01823f27cae6bf7850becb
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
86b744454fe78d825cf561fb57cbb757cf99b8ba
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
88a0149070a70e6b4eb662954355ef10aaccb19be7db3ea35a1275754676b0f1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e6abdb94f23bf3b590c9c2bf7e8d6ff88dadc459a60e4ee2d4c97bf83ef2466c7c66bc5aabeb5858d7b39f459de972ac8de8a27296ff0beb188a351a4ee204c2
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{
2+
"formatVersion": "1.1",
3+
"component": {
4+
"group": "com.virtusize.android",
5+
"module": "virtusize-auth",
6+
"version": "1.0.2",
7+
"attributes": {
8+
"org.gradle.status": "release"
9+
}
10+
},
11+
"createdBy": {
12+
"gradle": {
13+
"version": "7.0.2"
14+
}
15+
},
16+
"variants": [
17+
{
18+
"name": "releaseApiPublication",
19+
"attributes": {
20+
"org.gradle.category": "library",
21+
"org.gradle.dependency.bundling": "external",
22+
"org.gradle.libraryelements": "aar",
23+
"org.gradle.usage": "java-api"
24+
},
25+
"dependencies": [
26+
{
27+
"group": "org.jetbrains.kotlin",
28+
"module": "kotlin-stdlib-jdk8",
29+
"version": {
30+
"requires": "1.5.31"
31+
}
32+
}
33+
],
34+
"files": [
35+
{
36+
"name": "virtusize-auth-1.0.2.aar",
37+
"url": "virtusize-auth-1.0.2.aar",
38+
"size": 64597,
39+
"sha512": "e6abdb94f23bf3b590c9c2bf7e8d6ff88dadc459a60e4ee2d4c97bf83ef2466c7c66bc5aabeb5858d7b39f459de972ac8de8a27296ff0beb188a351a4ee204c2",
40+
"sha256": "88a0149070a70e6b4eb662954355ef10aaccb19be7db3ea35a1275754676b0f1",
41+
"sha1": "86b744454fe78d825cf561fb57cbb757cf99b8ba",
42+
"md5": "91f72416de01823f27cae6bf7850becb"
43+
}
44+
]
45+
},
46+
{
47+
"name": "releaseRuntimePublication",
48+
"attributes": {
49+
"org.gradle.category": "library",
50+
"org.gradle.dependency.bundling": "external",
51+
"org.gradle.libraryelements": "aar",
52+
"org.gradle.usage": "java-runtime"
53+
},
54+
"dependencies": [
55+
{
56+
"group": "org.jetbrains.kotlin",
57+
"module": "kotlin-stdlib-jdk8",
58+
"version": {
59+
"requires": "1.5.31"
60+
}
61+
},
62+
{
63+
"group": "com.virtusize.android",
64+
"module": "virtusize-core",
65+
"version": {
66+
"requires": "2.4.2"
67+
}
68+
},
69+
{
70+
"group": "androidx.appcompat",
71+
"module": "appcompat",
72+
"version": {
73+
"requires": "1.3.1"
74+
}
75+
},
76+
{
77+
"group": "androidx.browser",
78+
"module": "browser",
79+
"version": {
80+
"requires": "1.3.0"
81+
}
82+
},
83+
{
84+
"group": "androidx.core",
85+
"module": "core-ktx",
86+
"version": {
87+
"requires": "1.6.0"
88+
}
89+
},
90+
{
91+
"group": "androidx.lifecycle",
92+
"module": "lifecycle-livedata-ktx",
93+
"version": {
94+
"requires": "2.3.1"
95+
}
96+
},
97+
{
98+
"group": "androidx.lifecycle",
99+
"module": "lifecycle-viewmodel-ktx",
100+
"version": {
101+
"requires": "2.3.1"
102+
}
103+
},
104+
{
105+
"group": "com.google.android.material",
106+
"module": "material",
107+
"version": {
108+
"requires": "1.4.0"
109+
}
110+
}
111+
],
112+
"files": [
113+
{
114+
"name": "virtusize-auth-1.0.2.aar",
115+
"url": "virtusize-auth-1.0.2.aar",
116+
"size": 64597,
117+
"sha512": "e6abdb94f23bf3b590c9c2bf7e8d6ff88dadc459a60e4ee2d4c97bf83ef2466c7c66bc5aabeb5858d7b39f459de972ac8de8a27296ff0beb188a351a4ee204c2",
118+
"sha256": "88a0149070a70e6b4eb662954355ef10aaccb19be7db3ea35a1275754676b0f1",
119+
"sha1": "86b744454fe78d825cf561fb57cbb757cf99b8ba",
120+
"md5": "91f72416de01823f27cae6bf7850becb"
121+
}
122+
]
123+
}
124+
]
125+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3f4126cd71b58ec06b3ad0799c21ad9d
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4ba8aef884da02ebee4a2fca58aa4d0958bbf17d
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b25af38d2663189158456a11b1867acae78f5e071c9aa3c851068d44c2b3d6b6

0 commit comments

Comments
 (0)