You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(KotlinSDK): Adding IAP support for the Kotlin SDK (#1662) (#1672)
This PR adds support for routing API requests through Identity-Aware
Proxy. This is done by putting an OIDC token in the header as
`Proxy-Authorization: Bearer <token>`. The OIDC is generated through
IamCredentialsClient.
To use, users need to provide their `iap_client_id` and
`iap_service_account_email` to the SDK's configuration payload.
```
Map<String, String> lookerConfig = new HashMap<>();
lookerConfig.put("base_url", "<Base_Url>");
lookerConfig.put("kotlin_http_transport", "JAVA_NET");
lookerConfig.put("client_id", "<Client_ID>");
lookerConfig.put("client_secret", "<Client_Secret>");
lookerConfig.put("iap_client_id", "<IAP_Client_ID>");
lookerConfig.put("iap_service_account_email", "<IAP_Service_Account_Email>);
ConfigurationProvider settings = ApiSettings.fromMap(lookerConfig);
Transport transport = new Transport(settings);
AuthSession session = new AuthSession(settings, transport);
LookerSDK sdk = new LookerSDK(session);
```
`iap_client_id` is the OAuth client ID that was set-up when configuring
the the identity-aware proxy.
`iap_service_account_email` is the service account that is authorized to
bypass IAP.
val params =mapOf(client_id to clientId, client_secret to clientSecret)
138
203
val body =UrlEncodedContent(params)
139
-
val token =
140
-
ok<AuthToken>(
204
+
205
+
val iapToken = fetchIapToken()
206
+
207
+
try {
208
+
val token = ok<AuthToken>(
141
209
transport.request<AuthToken>(
142
210
HttpMethod.POST,
143
211
"$apiPath/login",
144
212
emptyMap(),
145
213
body,
146
-
),
214
+
) { requestSettings ->
215
+
val headers = requestSettings.headers.toMutableMap()
216
+
iapToken?.let {
217
+
headers["Proxy-Authorization"] ="Bearer $it"
218
+
}
219
+
requestSettings.copy(headers = headers)
220
+
},
147
221
)
148
-
authToken = token
222
+
authToken = token
223
+
} catch (e:Exception) {
224
+
val isUsingIap =!config["iap_client_id"].isNullOrBlank() ||!config["iap_service_account_email"].isNullOrBlank()
225
+
226
+
val errorMessage =if (isUsingIap) {
227
+
"Authentication failed during login. \nPlease check your iap_client_id and iap_service_account_email fields, as well as your Looker credentials.\nDetails: ${e.message}"
228
+
} else {
229
+
"Authentication failed during login. \nPlease check your Looker client_id and client_secret.\nDetails: ${e.message}"
0 commit comments