OpenIDConnectionUtils { static String getOIDCProviderTokenEndpointAndRefreshToken(OkHttpClient client, Map<String, Object> wellKnownOpenIdConfiguration, String clientId, String refreshToken, String clientSecret, String accessToken, boolean shouldPersistUpdatedTokenInKubeConfig) { String oidcTokenEndpoint = getParametersFromDiscoveryResponse(wellKnownOpenIdConfiguration, TOKEN_ENDPOINT_PARAM); try { String freshAccessToken = OpenIDConnectionUtils.refreshToken(client, oidcTokenEndpoint, clientId, refreshToken, clientSecret, shouldPersistUpdatedTokenInKubeConfig); if (freshAccessToken != null) { accessToken = freshAccessToken; } } catch (Exception e) { LOGGER.warn("Could not refresh OIDC token: {}", e.getMessage()); } return accessToken; } private  OpenIDConnectionUtils(); static String resolveOIDCTokenFromAuthConfig(Map<String, String> currentAuthProviderConfig); static final String ID_TOKEN_KUBECONFIG; static final String ISSUER_KUBECONFIG; static final String REFRESH_TOKEN_KUBECONFIG; static final String REFRESH_TOKEN_PARAM; static final String GRANT_TYPE_PARAM; static final String CLIENT_ID_PARAM; static final String CLIENT_SECRET_PARAM; static final String ID_TOKEN_PARAM; static final String ACCESS_TOKEN_PARAM; static final String CLIENT_ID_KUBECONFIG; static final String CLIENT_SECRET_KUBECONFIG; static final String IDP_CERT_DATA; static final String TOKEN_ENDPOINT_PARAM; static final String WELL_KNOWN_OPENID_CONFIGURATION; static final String GRANT_TYPE_REFRESH_TOKEN; }
@Test void testFetchOIDCProviderDiscoveryDocumentAndRefreshToken() throws IOException { Map<String, Object> discoveryDocument = new HashMap<>(); discoveryDocument.put(TOKEN_ENDPOINT_PARAM, "https: String accessToken = "some.access.token"; String clientId = "test-client-id"; String refreshToken = "test-refresh-token"; String clientSecret = "test-client-secret"; mockOkHttpClient(HttpURLConnection.HTTP_OK, "{\""+ ID_TOKEN_PARAM +"\":\"thisisatesttoken\",\"access_token\": \"thisisrefreshtoken\"," + "\"expires_in\": 3599," + "\"scope\": \"openid https: "\"token_type\": \"Bearer\"}"); String newAccessToken = OpenIDConnectionUtils.getOIDCProviderTokenEndpointAndRefreshToken(mockClient, discoveryDocument, clientId, refreshToken, clientSecret, accessToken, false); assertNotNull(newAccessToken); assertEquals("thisisatesttoken", newAccessToken); }