-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainApplication.kt
More file actions
43 lines (36 loc) · 1.41 KB
/
MainApplication.kt
File metadata and controls
43 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.azuresamples.msalnativeauthandroidkotlinsampleapp
import android.app.Application
import android.util.Log
import org.json.JSONObject
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
Log.d("MS", "Application onCreate called")
initializeProveIfConfigured()
}
private fun initializeProveIfConfigured() {
// Read Prove credentials directly from the packaged config file:
// `app/src/main/assets/config.json`
val (clientId, clientSecret) = try {
val jsonText = assets.open("config.json").bufferedReader().use { it.readText() }
val proveJson = JSONObject(jsonText).optJSONObject("Prove")
val id = proveJson?.optString("clientId").orEmpty().trim()
val secret = proveJson?.optString("clientSecret").orEmpty().trim()
id to secret
} catch (t: Throwable) {
Log.e("MS", "Failed to read Prove config from assets/config.json", t)
"" to ""
}
if (clientId.isBlank() || clientSecret.isBlank()) {
Log.w(
"MS",
"Prove not initialized. Set Prove.clientId and Prove.clientSecret in app/src/main/assets/config.json."
)
return
}
ProveManager.getInstance().initialize(
clientId = clientId,
clientSecret = clientSecret
)
}
}