Skip to content

Commit 8483520

Browse files
committed
doc: JavaDoc updates to WebBridge & Web authentication classes
1 parent dd4105b commit 8483520

File tree

4 files changed

+110
-18
lines changed

4 files changed

+110
-18
lines changed

library/src/main/java/com/sap/cdc/android/sdk/feature/provider/web/WebAuthenticationProvider.kt

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,22 @@ import kotlin.coroutines.resumeWithException
3030
import kotlin.coroutines.suspendCoroutine
3131

3232
/**
33-
* Created by Tal Mirmelshtein on 10/06/2024
33+
* Web-based social authentication provider.
34+
*
35+
* Implements social login using WebView for providers that don't have native SDK support.
36+
* Handles OAuth 1.0a flow with the CDC socialize.login endpoint.
37+
*
38+
* @property socialProvider Social provider identifier (e.g., "twitter", "linkedin")
39+
* @property siteConfig CDC site configuration
40+
* @property session Optional existing session for authenticated requests
41+
*
42+
* @author Tal Mirmelshtein
43+
* @since 10/06/2024
44+
*
3445
* Copyright: SAP LTD.
46+
*
47+
* @see IAuthenticationProvider
48+
* @see WebLoginActivity
3549
*/
3650
class WebAuthenticationProvider(
3751
private val socialProvider: String,
@@ -138,7 +152,10 @@ class WebAuthenticationProvider(
138152
}
139153

140154
/**
141-
* Generate authentication URI.
155+
* Generates the OAuth authentication URI for social login.
156+
* Includes GMID, nonce, and optional session signing for authenticated requests.
157+
* @param hostActivity Host activity for package name in redirect URI
158+
* @return Complete authentication URL
142159
*/
143160
private fun generateUri(hostActivity: ComponentActivity): String {
144161
// Fetch gmid
@@ -180,7 +197,10 @@ class WebAuthenticationProvider(
180197
}
181198

182199
/**
183-
* Parse result session information.
200+
* Parses session information from the authentication result.
201+
* Extracts access token, secret, and expiration from intent extras.
202+
* @param result Result intent containing session data
203+
* @return Session object with credentials
184204
*/
185205
private fun handleSessionInfo(result: Intent): Session {
186206
// Parse session information.
@@ -197,7 +217,10 @@ class WebAuthenticationProvider(
197217
}
198218

199219
/**
200-
* Parse error information. May result in a continuous flow to resolve the error.
220+
* Parses error information from the authentication result.
221+
* Extracts error code and message, optionally includes registration token.
222+
* @param result Result intent containing error data
223+
* @return CDCError with parsed error details
201224
*/
202225
//TODO: Change flow to base response. Not handling CDCError as a object.
203226
private fun handleErrorInfo(result: Intent): CDCError {
@@ -227,4 +250,4 @@ class WebAuthenticationProvider(
227250
launcher?.unregister()
228251
}
229252

230-
}
253+
}

library/src/main/java/com/sap/cdc/android/sdk/feature/provider/web/WebLoginActivity.kt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@ import com.sap.cdc.android.sdk.R
1919
import com.sap.cdc.android.sdk.extensions.parseQueryStringParams
2020

2121
/**
22-
* Created by Tal Mirmelshtein on 10/06/2024
22+
* WebView-based login activity for social authentication.
23+
*
24+
* Displays a WebView for OAuth authentication with social providers that don't
25+
* have native SDK support. Handles URL interception for OAuth callbacks and
26+
* extracts authentication tokens from the redirect URI.
27+
*
28+
* @author Tal Mirmelshtein
29+
* @since 10/06/2024
30+
*
2331
* Copyright: SAP LTD.
32+
*
33+
* @see WebAuthenticationProvider
2434
*/
25-
2635
class WebLoginActivity : ComponentActivity() {
2736

2837
companion object {
@@ -64,10 +73,11 @@ class WebLoginActivity : ComponentActivity() {
6473
webView.loadUrl(uri!!)
6574
}
6675

67-
@SuppressLint("SetJavaScriptEnabled")
6876
/**
69-
* Setting up main WebView widget.
77+
* Configures the WebView with JavaScript enabled and custom WebViewClient.
78+
* Handles page load progress and URL interception for OAuth callbacks.
7079
*/
80+
@SuppressLint("SetJavaScriptEnabled")
7181
private fun setupWebViewElement() {
7282
webView.settings.setSupportZoom(true)
7383
webView.settings.builtInZoomControls = true
@@ -103,7 +113,10 @@ class WebLoginActivity : ComponentActivity() {
103113
}
104114

105115
/**
106-
* Check login result on URL loading.
116+
* Checks if the current URL is the OAuth redirect callback.
117+
* Extracts authentication parameters from the URL fragment and returns them.
118+
* @param uri The URI to check
119+
* @return true if this is the callback URL, false otherwise
107120
*/
108121
private fun loginResult(uri: Uri?): Boolean {
109122
if (uri == null) return false
@@ -137,11 +150,11 @@ class WebLoginActivity : ComponentActivity() {
137150
}
138151

139152
/**
140-
* Cancel flow on back press.
153+
* Handles back button press by canceling the authentication flow.
141154
*/
142155
override fun getOnBackInvokedDispatcher(): OnBackInvokedDispatcher {
143156
setResult(RESULT_CANCELED)
144157
return super.getOnBackInvokedDispatcher()
145158
}
146159

147-
}
160+
}

library/src/main/java/com/sap/cdc/android/sdk/feature/screensets/ScreenSetsResult.kt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@ package com.sap.cdc.android.sdk.feature.screensets
33
import com.sap.cdc.android.sdk.core.api.model.CDCError
44

55
/**
6-
* Event data for ScreenSets events
6+
* Event data container for ScreenSets lifecycle events.
7+
*
8+
* Contains information about web-based authentication UI events triggered
9+
* by user interactions or system state changes.
10+
*
11+
* @property eventName The name of the event (e.g., "load", "login", "error")
12+
* @property content Optional map containing event-specific data
13+
* @property screenSetId Identifier of the screen set that triggered the event
14+
* @property sourceContainerID Container ID where the event originated
15+
*
16+
* @see ScreenSetsCallbacks
17+
* @see WebBridgeJS
718
*/
819
data class ScreenSetsEventData(
920
val eventName: String,
@@ -13,7 +24,18 @@ data class ScreenSetsEventData(
1324
)
1425

1526
/**
16-
* Error information for ScreenSets events
27+
* Error information for ScreenSets operations.
28+
*
29+
* Wraps error details from web-based authentication flows, providing
30+
* context about what went wrong and where.
31+
*
32+
* @property message Human-readable error message
33+
* @property eventName Name of the event where the error occurred
34+
* @property cdcError Structured CDC error object if available
35+
* @property details Additional error context and metadata
36+
*
37+
* @see CDCError
38+
* @see ScreenSetsCallbacks.onError
1739
*/
1840
data class ScreenSetsError(
1941
val message: String,
@@ -23,9 +45,24 @@ data class ScreenSetsError(
2345
)
2446

2547
/**
26-
* Sealed class representing the result of ScreenSets operations
48+
* Sealed class representing ScreenSets operation results.
49+
*
50+
* Provides type-safe handling of either successful events or errors
51+
* from web-based authentication flows.
52+
*
53+
* @see ScreenSetsEventData
54+
* @see ScreenSetsError
2755
*/
2856
sealed class ScreenSetsResult {
57+
/**
58+
* Successful event result.
59+
* @property eventData The event data
60+
*/
2961
data class Event(val eventData: ScreenSetsEventData) : ScreenSetsResult()
62+
63+
/**
64+
* Error result.
65+
* @property screenSetsError The error information
66+
*/
3067
data class Error(val screenSetsError: ScreenSetsError) : ScreenSetsResult()
3168
}

library/src/main/java/com/sap/cdc/android/sdk/feature/screensets/WebBridgeJSEvent.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@ package com.sap.cdc.android.sdk.feature.screensets
33
import com.sap.cdc.android.sdk.core.api.model.CDCError
44

55
/**
6-
* Created by Tal Mirmelshtein on 13/06/2024
6+
* Event wrapper for JavaScript bridge communication.
7+
*
8+
* Encapsulates events from web-based ScreenSets, providing type-safe access
9+
* to event data and factory methods for common events.
10+
*
11+
* @property content Map containing event data including eventName and payload
12+
*
13+
* @author Tal Mirmelshtein
14+
* @since 13/06/2024
15+
*
716
* Copyright: SAP LTD.
17+
*
18+
* @see WebBridgeJS
19+
* @see ScreenSetsEventData
820
*/
921
class WebBridgeJSEvent(
1022
val content: Map<String, Any?>? = mapOf()
@@ -52,10 +64,17 @@ class WebBridgeJSEvent(
5264
}
5365

5466
/**
55-
* Data class to hold JS evaluation request data.
67+
* Container for JavaScript evaluation requests.
68+
*
69+
* Holds data required to evaluate JavaScript in the WebView and
70+
* optionally trigger follow-up events.
71+
*
72+
* @property containerID The container ID where evaluation should occur
73+
* @property evaluationString The JavaScript code to evaluate
74+
* @property event Optional event to trigger after evaluation
5675
*/
5776
data class WebBridgeJSEvaluation(
5877
val containerID: String,
5978
val evaluationString: String,
6079
val event: WebBridgeJSEvent?
61-
)
80+
)

0 commit comments

Comments
 (0)