Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ vNext
- [PATCH] Fix caching of secret key and add retries for InvalidKeyException during unwrap (#2659)
- [MINOR] Replace AbstractSecretKeyLoader with ISecretKeyProvider (#2666)
- [MINOR] Update IP phone app teams signature constants to use SHA-512 format (#2700)
- [PATCH] Fix a few small switch browser bugs (#2710)

Version 21.4.0
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ else if (isRedirectUrl(formattedURL)) {
Logger.info(methodTag,"Navigation starts with the redirect uri.");
if (mSwitchBrowserRequestHandler.isSwitchBrowserRequest(formattedURL, mRedirectUrl)) {
Logger.info(methodTag,"Request to switch browser.");
processSwitchBrowserRequest(formattedURL);
processSwitchBrowserRequest(url);
} else {
Logger.info(methodTag,"It is a redirect request.");
processRedirectUrl(view, url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ class SwitchBrowserProtocolCoordinator(
SwitchBrowserUriHelper.statesMatch(authorizationRequest, state)
// Validate the state from auth request and redirect URL is the same
val resumeUri = SwitchBrowserUriHelper.buildResumeUri(actionUri, state)
val headers = hashMapOf(AUTHORIZATION to code)
val authorizationHeaderValue = "Bearer $code"
val headers = hashMapOf(AUTHORIZATION to authorizationHeaderValue)
onSuccessAction(resumeUri, headers)
// Reset the challenge state after processing the resume action
switchBrowserRequestHandler.resetChallengeState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,10 @@ object SwitchBrowserUriHelper {
actionUri: String,
queryParams: HashMap<String, String> = hashMapOf()
): Uri {
val paths = actionUri.split("/")
val authority = paths[0]
val uriBuilder = Uri.Builder()
.scheme("https")
.encodedAuthority(authority)
for (i in 1 until paths.size) {
uriBuilder.appendPath(paths[i])
}
val uri = Uri.parse(actionUri)

val uriBuilder = uri.buildUpon()

for ((key, value) in queryParams.entries) {
uriBuilder.appendQueryParameter(key, value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package com.microsoft.identity.common.internal.ui.webview.switchbrowser

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import com.microsoft.identity.common.adal.internal.AuthenticationConstants.AuthorizationIntentKey.AUTHORIZATION_AGENT
import com.microsoft.identity.common.adal.internal.AuthenticationConstants.Broker
Expand Down Expand Up @@ -52,7 +53,7 @@ class SwitchBrowserProtocolCoordinatorTest {
val mockSwitchBrowserRequestHandler = mock(SwitchBrowserRequestHandler::class.java)
doNothing().`when`(mockSwitchBrowserRequestHandler).resetChallengeState()
val code = "switch_browser_code"
val actionUrl = "test.example.com/switchbrowser/path"
val actionUrl = "https://test.example.com/switchbrowser/path"
val state = "123"
val extras = Bundle().apply {
putString(SWITCH_BROWSER.CODE, code)
Expand All @@ -65,8 +66,11 @@ class SwitchBrowserProtocolCoordinatorTest {
// Call the method to be tested
coordinator.processSwitchBrowserResume("https://auth.com?state=$state",extras) { uri, headers ->
// Verify the resume URI
Assert.assertEquals(actionUrl, uri.host + uri.path)
Assert.assertEquals(code, headers[AUTHORIZATION])
val actionUri = Uri.parse(actionUrl)
Assert.assertEquals(actionUri.scheme, uri.scheme)
Assert.assertEquals(actionUri.host, uri.host)
Assert.assertEquals(actionUri.path, uri.path)
Assert.assertEquals("Bearer $code", headers[AUTHORIZATION])
}
}

Expand All @@ -77,7 +81,7 @@ class SwitchBrowserProtocolCoordinatorTest {
val mockSwitchBrowserRequestHandler = mock(SwitchBrowserRequestHandler::class.java)
doNothing().`when`(mockSwitchBrowserRequestHandler).resetChallengeState()
val code = "switch_browser_code"
val actionUrl = "test.example.com/switchbrowser/path"
val actionUrl = "https://test.example.com/switchbrowser/path"
val extras = Bundle().apply {
putString(SWITCH_BROWSER.CODE, code)
putString(SWITCH_BROWSER.ACTION_URI, actionUrl)
Expand All @@ -88,8 +92,11 @@ class SwitchBrowserProtocolCoordinatorTest {
// Call the method to be tested
coordinator.processSwitchBrowserResume("https://auth.com",extras) { uri, headers ->
// Verify the resume URI
Assert.assertEquals(actionUrl, uri.host + uri.path)
Assert.assertEquals(code, headers[AUTHORIZATION])
val actionUri = Uri.parse(actionUrl)
Assert.assertEquals(actionUri.scheme, uri.scheme)
Assert.assertEquals(actionUri.host, uri.host)
Assert.assertEquals(actionUri.path, uri.path)
Assert.assertEquals("Bearer $code", headers[AUTHORIZATION])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SwitchBrowserUriHelperTest {

companion object {
private const val CODE = "your-switch-browser-code"
private const val ACTION_URI = "login.microsoftonline.com/switchbrowser/process"
private const val ACTION_URI = "https://login.microsoftonline.com/switchbrowser/process"
private const val STATE = "123"
}

Expand All @@ -57,10 +57,10 @@ class SwitchBrowserUriHelperTest {
CODE,
switchBrowserProcessUri.getQueryParameter(SWITCH_BROWSER.CODE)
)
Assert.assertEquals(
ACTION_URI,
switchBrowserProcessUri.host + switchBrowserProcessUri.path
)
val actionUri = Uri.parse(ACTION_URI)
Assert.assertEquals(actionUri.scheme, switchBrowserProcessUri.scheme)
Assert.assertEquals(actionUri.host, switchBrowserProcessUri.host)
Assert.assertEquals(actionUri.path, switchBrowserProcessUri.path)
Assert.assertEquals(
STATE,
switchBrowserProcessUri.getQueryParameter(SWITCH_BROWSER.STATE)
Expand All @@ -81,10 +81,10 @@ class SwitchBrowserUriHelperTest {
CODE,
switchBrowserProcessUri.getQueryParameter(SWITCH_BROWSER.CODE)
)
Assert.assertEquals(
ACTION_URI,
switchBrowserProcessUri.host + switchBrowserProcessUri.path
)
val actionUri = Uri.parse(ACTION_URI)
Assert.assertEquals(actionUri.scheme, switchBrowserProcessUri.scheme)
Assert.assertEquals(actionUri.host, switchBrowserProcessUri.host)
Assert.assertEquals(actionUri.path, switchBrowserProcessUri.path)
}

@Test
Expand Down Expand Up @@ -142,10 +142,10 @@ class SwitchBrowserUriHelperTest {
ACTION_URI, null
)
Assert.assertNotNull(uri)
Assert.assertEquals(
ACTION_URI,
uri.host + uri.path
)
val actionUri = Uri.parse(ACTION_URI)
Assert.assertEquals(actionUri.scheme, uri.scheme)
Assert.assertEquals(actionUri.host, uri.host)
Assert.assertEquals(actionUri.path, uri.path)
Assert.assertNull(uri.getQueryParameter(SWITCH_BROWSER.STATE))
}

Expand All @@ -155,10 +155,10 @@ class SwitchBrowserUriHelperTest {
ACTION_URI, STATE
)
Assert.assertNotNull(uri)
Assert.assertEquals(
ACTION_URI,
uri.host + uri.path
)
val actionUri = Uri.parse(ACTION_URI)
Assert.assertEquals(actionUri.scheme, uri.scheme)
Assert.assertEquals(actionUri.host, uri.host)
Assert.assertEquals(actionUri.path, uri.path)
Assert.assertEquals(
STATE,
uri.getQueryParameter(SWITCH_BROWSER.STATE)
Expand Down
Loading