Skip to content

Commit

Permalink
addressed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lalwani committed Mar 14, 2024
1 parent 6ec18ec commit 1c8a3c3
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ object SsoConfigProvider {
val resourceId = resources.getIdentifier(SSO_CONFIG_FILE, "raw", context.packageName)
val configSource: BufferedSource =
Okio.buffer(Okio.source(resources.openRawResource(resourceId)))
val configData = Buffer()
try {
configSource.readAll(configData)
val configJson = JSONObject(configData.readString(Charset.forName("UTF-8")))
val clientId = getRequiredConfigString(configJson, CLIENT_ID_PARAM)
val scope = getConfigString(configJson, SCOPE_PARAM)
val redirectUri = getRequiredConfigString(configJson, REDIRECT_PARAM)
configSource.close()
return SsoConfig(clientId, redirectUri, scope)
} catch (ex: IOException) {
throw AuthException.ClientError("Failed to read configuration: " + ex.message)
} catch (ex: JSONException) {
throw AuthException.ClientError("Failed to read configuration: " + ex.message)
configSource.use {
val configData = Buffer()
try {
configSource.readAll(configData)
val configJson = JSONObject(configData.readString(Charset.forName("UTF-8")))
val clientId = getRequiredConfigString(configJson, CLIENT_ID_PARAM)
val scope = getConfigString(configJson, SCOPE_PARAM)
val redirectUri = getRequiredConfigString(configJson, REDIRECT_PARAM)
return SsoConfig(clientId, redirectUri, scope)
} catch (ex: IOException) {
throw AuthException.ClientError("Failed to read configuration: " + ex.message)
} catch (ex: JSONException) {
throw AuthException.ClientError("Failed to read configuration: " + ex.message)
}
}
}

Expand All @@ -63,11 +64,8 @@ object SsoConfigProvider {
}

private fun getConfigString(configJson: JSONObject, propName: String): String? {
var value: String = configJson.optString(propName) ?: return null
value = value.trim { it <= ' ' }
return if (TextUtils.isEmpty(value)) {
null
} else value
val value: String = configJson.optString(propName) ?: return null
return value.trim { it <= ' ' }.takeIf { it.isNotEmpty() }
}

private const val SSO_CONFIG_FILE = "sso_config"
Expand Down

0 comments on commit 1c8a3c3

Please sign in to comment.