@@ -130,58 +130,47 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
130130 }
131131
132132 /* *
133- * Stores the given [SSOCredentials] refresh token in the storage.
134- * This method must be called if the SSOCredentials are obtained by directly invoking [AuthenticationAPIClient.fetchWebSsoToken] api and
135- * [rotating refresh token](https://auth0.com/docs/secure/tokens/refresh-tokens/refresh-token-rotation) are enabled for
136- * the client. Method will silently return ,if the passed credentials has no refresh token.
137- * This is still an experimental feature, test it thoroughly in the targeted devices and OS variants and let us know your feedback.
138- *
139- * @param ssoCredentials the credentials to save in the storage.
133+ * Fetches a new [SSOCredentials] . It will fail with [CredentialsManagerException]
134+ * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token,
135+ * if a new one is issued.
136+ * This is still an experimental feature, test it thoroughly and let us know your feedback.
140137 */
141138 @ExperimentalAuth0Api
142- override fun saveSsoCredentials (ssoCredentials : SSOCredentials ) {
143- if (ssoCredentials.refreshToken.isNullOrEmpty()) return // No refresh token to save
144- serialExecutor.execute {
145- lateinit var existingCredentials: Credentials
146- try {
147- existingCredentials = getExistingCredentials()
148- } catch (exception: CredentialsManagerException ) {
149- Log .e(TAG ," Error while fetching existing credentials" , exception)
150- return @execute
151- }
152- // Checking if the existing one needs to be replaced with the new one
153- if (existingCredentials.refreshToken == ssoCredentials.refreshToken)
154- return @execute
155- val newCredentials =
156- existingCredentials.copy(refreshToken = ssoCredentials.refreshToken)
157- saveCredentials(newCredentials)
158- }
139+ override fun getSsoCredentials (callback : Callback <SSOCredentials , CredentialsManagerException >) {
140+ getSsoCredentials(emptyMap(), callback)
159141 }
160142
161143 /* *
162144 * Fetches a new [SSOCredentials] . It will fail with [CredentialsManagerException]
163145 * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token,
164146 * if a new one is issued.
165- * This is still an experimental feature, test it thoroughly in the targeted devices and OS variants and let us know your feedback.
147+ * This is still an experimental feature, test it thoroughly and let us know your feedback.
166148 */
167149 @ExperimentalAuth0Api
168- override fun getSsoCredentials (callback : Callback <SSOCredentials , CredentialsManagerException >) {
150+ override fun getSsoCredentials (
151+ headers : Map <String , String >,
152+ callback : Callback <SSOCredentials , CredentialsManagerException >
153+ ) {
169154 serialExecutor.execute {
170- lateinit var existingCredentials: Credentials
171- try {
155+ lateinit var existingCredentials: Credentials
156+ try {
172157 existingCredentials = getExistingCredentials()
173- }catch (exception: CredentialsManagerException ){
158+ } catch (exception: CredentialsManagerException ) {
174159 callback.onFailure(exception)
175160 return @execute
176161 }
177162 if (existingCredentials.refreshToken.isNullOrEmpty()) {
178163 callback.onFailure(CredentialsManagerException .NO_REFRESH_TOKEN )
179164 return @execute
180165 }
166+
167+ val request = authenticationClient.fetchWebSsoToken(existingCredentials.refreshToken!! )
181168 try {
169+ for (header in headers) {
170+ request.addHeader(header.key, header.value)
171+ }
182172 val sessionCredentials =
183- authenticationClient.fetchWebSsoToken(existingCredentials.refreshToken!! )
184- .execute()
173+ request.execute()
185174 saveSsoCredentials(sessionCredentials)
186175 callback.onSuccess(sessionCredentials)
187176 } catch (error: AuthenticationException ) {
@@ -211,22 +200,36 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
211200 * Fetches a new [SSOCredentials] . It will fail with [CredentialsManagerException]
212201 * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token,
213202 * if a new one is issued.
214- * This is still an experimental feature, test it thoroughly in the targeted devices and OS variants and let us know your feedback.
203+ * This is still an experimental feature, test it thoroughly and let us know your feedback.
215204 */
216205 @JvmSynthetic
217206 @Throws(CredentialsManagerException ::class )
218207 @ExperimentalAuth0Api
219208 override suspend fun awaitSsoCredentials (): SSOCredentials {
209+ return awaitSsoCredentials(emptyMap())
210+ }
211+
212+ /* *
213+ * Fetches a new [SSOCredentials] . It will fail with [CredentialsManagerException]
214+ * if the existing refresh_token is null or no longer valid. This method will handle saving the refresh_token,
215+ * if a new one is issued.
216+ * This is still an experimental feature, test it thoroughly and let us know your feedback.
217+ */
218+ @JvmSynthetic
219+ @Throws(CredentialsManagerException ::class )
220+ @ExperimentalAuth0Api
221+ override suspend fun awaitSsoCredentials (headers : Map <String , String >): SSOCredentials {
220222 return suspendCancellableCoroutine { continuation ->
221- getSsoCredentials(object : Callback <SSOCredentials , CredentialsManagerException > {
222- override fun onSuccess (result : SSOCredentials ) {
223- continuation.resume(result)
224- }
223+ getSsoCredentials(headers,
224+ object : Callback <SSOCredentials , CredentialsManagerException > {
225+ override fun onSuccess (result : SSOCredentials ) {
226+ continuation.resume(result)
227+ }
225228
226- override fun onFailure (error : CredentialsManagerException ) {
227- continuation.resumeWithException(error)
228- }
229- })
229+ override fun onFailure (error : CredentialsManagerException ) {
230+ continuation.resumeWithException(error)
231+ }
232+ })
230233 }
231234 }
232235
@@ -763,6 +766,30 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
763766 fragmentActivity!! .clear()
764767 }
765768
769+ /* *
770+ * Helper method to stores the given [SSOCredentials] refresh token in the storage.
771+ * Method will silently return ,if the passed credentials has no refresh token.
772+ *
773+ * @param ssoCredentials the credentials to save in the storage.
774+ */
775+ @VisibleForTesting(otherwise = VisibleForTesting .PRIVATE )
776+ internal fun saveSsoCredentials (ssoCredentials : SSOCredentials ) {
777+ if (ssoCredentials.refreshToken.isNullOrEmpty()) return // No refresh token to save
778+ lateinit var existingCredentials: Credentials
779+ try {
780+ existingCredentials = getExistingCredentials()
781+ } catch (exception: CredentialsManagerException ) {
782+ Log .e(TAG , " Error while fetching existing credentials" , exception)
783+ return
784+ }
785+ // Checking if the existing one needs to be replaced with the new one
786+ if (existingCredentials.refreshToken == ssoCredentials.refreshToken)
787+ return
788+ val newCredentials =
789+ existingCredentials.copy(refreshToken = ssoCredentials.refreshToken)
790+ saveCredentials(newCredentials)
791+ }
792+
766793 internal companion object {
767794 private val TAG = SecureCredentialsManager ::class .java.simpleName
768795
0 commit comments