Skip to content

Commit 91e60ae

Browse files
authored
Native auth: network layer for JIT feature, Fixes AB#3188135 (#2626)
Adding network layer for JIT feature. Integration tests are written for the NativeAuthOAuth2Strategy class. To write tests for this class, I need to create new commandParameters classes. Since these classes are more related to the business logic, I decided to add them and the integration tests in the next PR. [AB#3188135](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3188135)
1 parent 79a10e7 commit 91e60ae

File tree

24 files changed

+1799
-103
lines changed

24 files changed

+1799
-103
lines changed

common/src/main/java/com/microsoft/identity/common/nativeauth/internal/controllers/NativeAuthMsalController.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,11 @@ class NativeAuthMsalController : BaseNativeAuthController() {
223223
tokenApiResult = tokenApiResult
224224
)
225225
}
226+
// TODO: this will need to change in JIT business logic PR
226227
is SignInTokenApiResult.InvalidAuthenticationType,
227228
is SignInTokenApiResult.MFARequired, is SignInTokenApiResult.CodeIncorrect,
228229
is SignInTokenApiResult.UserNotFound, is SignInTokenApiResult.InvalidCredentials,
229-
is SignInTokenApiResult.UnknownError -> {
230+
is SignInTokenApiResult.UnknownError, is SignInTokenApiResult.JITRequired -> {
230231
Logger.warnWithObject(
231232
TAG,
232233
tokenApiResult.correlationId,
@@ -298,10 +299,10 @@ class NativeAuthMsalController : BaseNativeAuthController() {
298299
correlationId = tokenApiResult.correlationId
299300
)
300301
}
301-
302+
// TODO: this will need to change in JIT business logic PR
302303
is SignInTokenApiResult.UnknownError, is SignInTokenApiResult.InvalidAuthenticationType,
303304
is SignInTokenApiResult.MFARequired, is SignInTokenApiResult.InvalidCredentials,
304-
is SignInTokenApiResult.UserNotFound -> {
305+
is SignInTokenApiResult.UserNotFound, is SignInTokenApiResult.JITRequired -> {
305306
Logger.warnWithObject(
306307
TAG,
307308
tokenApiResult.correlationId,
@@ -351,6 +352,7 @@ class NativeAuthMsalController : BaseNativeAuthController() {
351352
oAuth2Strategy = oAuth2Strategy,
352353
parameters = parametersWithScopes
353354
)
355+
// TODO: this will need to change in JIT business logic PR
354356
return when (tokenApiResult) {
355357
is SignInTokenApiResult.Success -> {
356358
saveAndReturnTokens(
@@ -370,7 +372,7 @@ class NativeAuthMsalController : BaseNativeAuthController() {
370372
}
371373
is SignInTokenApiResult.UnknownError, is SignInTokenApiResult.InvalidAuthenticationType,
372374
is SignInTokenApiResult.InvalidCredentials, is SignInTokenApiResult.UserNotFound,
373-
is SignInTokenApiResult.MFARequired -> {
375+
is SignInTokenApiResult.MFARequired, is SignInTokenApiResult.JITRequired -> {
374376
Logger.warnWithObject(
375377
TAG,
376378
tokenApiResult.correlationId,
@@ -2117,6 +2119,7 @@ class NativeAuthMsalController : BaseNativeAuthController() {
21172119
oAuth2Strategy: NativeAuthOAuth2Strategy,
21182120
parametersWithScopes: SignInStartCommandParameters,
21192121
): SignInStartCommandResult {
2122+
// TODO: this will need to change in JIT business logic PR
21202123
return when (this) {
21212124
is SignInTokenApiResult.InvalidCredentials -> {
21222125
SignInCommandResult.InvalidCredentials(
@@ -2145,7 +2148,7 @@ class NativeAuthMsalController : BaseNativeAuthController() {
21452148
}
21462149
is SignInTokenApiResult.CodeIncorrect,
21472150
is SignInTokenApiResult.InvalidAuthenticationType, is SignInTokenApiResult.UserNotFound,
2148-
is SignInTokenApiResult.UnknownError -> {
2151+
is SignInTokenApiResult.UnknownError, is SignInTokenApiResult.JITRequired -> {
21492152
Logger.warnWithObject(
21502153
TAG,
21512154
this.correlationId,
@@ -2167,6 +2170,7 @@ class NativeAuthMsalController : BaseNativeAuthController() {
21672170
oAuth2Strategy: NativeAuthOAuth2Strategy,
21682171
parametersWithScopes: SignInSubmitPasswordCommandParameters,
21692172
): SignInSubmitPasswordCommandResult {
2173+
// TODO: this will need to change in JIT business logic PR
21702174
return when (this) {
21712175
is SignInTokenApiResult.InvalidCredentials -> {
21722176
SignInCommandResult.InvalidCredentials(
@@ -2194,7 +2198,8 @@ class NativeAuthMsalController : BaseNativeAuthController() {
21942198
)
21952199
}
21962200
is SignInTokenApiResult.UserNotFound, is SignInTokenApiResult.CodeIncorrect,
2197-
is SignInTokenApiResult.InvalidAuthenticationType, is SignInTokenApiResult.UnknownError -> {
2201+
is SignInTokenApiResult.InvalidAuthenticationType, is SignInTokenApiResult.UnknownError,
2202+
is SignInTokenApiResult.JITRequired -> {
21982203
Logger.warnWithObject(
21992204
TAG,
22002205
this.correlationId,

common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/ResetPasswordOAuth2StrategyTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class ResetPasswordOAuth2StrategyTest {
114114
whenever(mockConfig.getResetPasswordContinueEndpoint()).thenReturn(ApiConstants.MockApi.ssprContinueRequestUrl)
115115
whenever(mockConfig.getResetPasswordSubmitEndpoint()).thenReturn(ApiConstants.MockApi.ssprSubmitRequestUrl)
116116
whenever(mockConfig.getResetPasswordPollCompletionEndpoint()).thenReturn(ApiConstants.MockApi.ssprPollCompletionRequestUrl)
117+
whenever(mockConfig.getJITIntrospectEndpoint()).thenReturn(ApiConstants.MockApi.jitIntrospectRequestUrl)
118+
whenever(mockConfig.getJITChallengeEndpoint()).thenReturn(ApiConstants.MockApi.jitChallengeRequestUrl)
119+
whenever(mockConfig.getJITContinueEndpoint()).thenReturn(ApiConstants.MockApi.jitContinueRequestUrl)
117120
whenever(mockConfig.challengeType).thenReturn(CHALLENGE_TYPE)
118121

119122
nativeAuthOAuth2Strategy = NativeAuthOAuth2Strategy(

common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/SignInOAuthStrategyTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class SignInOAuthStrategyTest {
102102
whenever(mockConfig.getResetPasswordContinueEndpoint()).thenReturn(ApiConstants.MockApi.ssprContinueRequestUrl)
103103
whenever(mockConfig.getResetPasswordSubmitEndpoint()).thenReturn(ApiConstants.MockApi.ssprSubmitRequestUrl)
104104
whenever(mockConfig.getResetPasswordPollCompletionEndpoint()).thenReturn(ApiConstants.MockApi.ssprPollCompletionRequestUrl)
105+
whenever(mockConfig.getJITIntrospectEndpoint()).thenReturn(ApiConstants.MockApi.jitIntrospectRequestUrl)
106+
whenever(mockConfig.getJITChallengeEndpoint()).thenReturn(ApiConstants.MockApi.jitChallengeRequestUrl)
107+
whenever(mockConfig.getJITContinueEndpoint()).thenReturn(ApiConstants.MockApi.jitContinueRequestUrl)
105108
whenever(mockConfig.challengeType).thenReturn(CHALLENGE_TYPE)
106109

107110
nativeAuthOAuth2Strategy = NativeAuthOAuth2Strategy(

common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/SignUpOAuth2StrategyTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class SignUpOAuth2StrategyTest {
101101
whenever(mockConfig.getResetPasswordContinueEndpoint()).thenReturn(ApiConstants.MockApi.ssprContinueRequestUrl)
102102
whenever(mockConfig.getResetPasswordSubmitEndpoint()).thenReturn(ApiConstants.MockApi.ssprSubmitRequestUrl)
103103
whenever(mockConfig.getResetPasswordPollCompletionEndpoint()).thenReturn(ApiConstants.MockApi.ssprPollCompletionRequestUrl)
104+
whenever(mockConfig.getJITIntrospectEndpoint()).thenReturn(ApiConstants.MockApi.jitIntrospectRequestUrl)
105+
whenever(mockConfig.getJITChallengeEndpoint()).thenReturn(ApiConstants.MockApi.jitChallengeRequestUrl)
106+
whenever(mockConfig.getJITContinueEndpoint()).thenReturn(ApiConstants.MockApi.jitContinueRequestUrl)
104107
whenever(mockConfig.challengeType).thenReturn(CHALLENGE_TYPE)
105108

106109
nativeAuthOAuth2Strategy = NativeAuthOAuth2Strategy(

common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/scenario/ResetPasswordScenarioTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class ResetPasswordScenarioTest {
8484
whenever(mockConfig.getResetPasswordContinueEndpoint()).thenReturn(ApiConstants.MockApi.ssprContinueRequestUrl)
8585
whenever(mockConfig.getResetPasswordSubmitEndpoint()).thenReturn(ApiConstants.MockApi.ssprSubmitRequestUrl)
8686
whenever(mockConfig.getResetPasswordPollCompletionEndpoint()).thenReturn(ApiConstants.MockApi.ssprPollCompletionRequestUrl)
87+
whenever(mockConfig.getJITIntrospectEndpoint()).thenReturn(ApiConstants.MockApi.jitIntrospectRequestUrl)
88+
whenever(mockConfig.getJITChallengeEndpoint()).thenReturn(ApiConstants.MockApi.jitChallengeRequestUrl)
89+
whenever(mockConfig.getJITContinueEndpoint()).thenReturn(ApiConstants.MockApi.jitContinueRequestUrl)
8790
whenever(mockConfig.challengeType).thenReturn(challengeType)
8891

8992
nativeAuthOAuth2Strategy = NativeAuthOAuth2Strategy(

common/src/test/java/com/microsoft/identity/common/internal/providers/microsoft/nativeauth/integration/scenario/SignUpScenarioTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class SignUpScenarioTest {
7878
whenever(mockConfig.getResetPasswordContinueEndpoint()).thenReturn(ApiConstants.MockApi.ssprContinueRequestUrl)
7979
whenever(mockConfig.getResetPasswordSubmitEndpoint()).thenReturn(ApiConstants.MockApi.ssprSubmitRequestUrl)
8080
whenever(mockConfig.getResetPasswordPollCompletionEndpoint()).thenReturn(ApiConstants.MockApi.ssprPollCompletionRequestUrl)
81+
whenever(mockConfig.getJITIntrospectEndpoint()).thenReturn(ApiConstants.MockApi.jitIntrospectRequestUrl)
82+
whenever(mockConfig.getJITChallengeEndpoint()).thenReturn(ApiConstants.MockApi.jitChallengeRequestUrl)
83+
whenever(mockConfig.getJITContinueEndpoint()).thenReturn(ApiConstants.MockApi.jitContinueRequestUrl)
8184
whenever(mockConfig.challengeType).thenReturn(CHALLENGE_TYPE)
8285

8386
nativeAuthOAuth2Strategy = NativeAuthOAuth2Strategy(

common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthOAuth2Configuration.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class NativeAuthOAuth2Configuration(
6363
private const val SIGN_IN_INTROSPECT_ENDPOINT_SUFFIX = "/oauth2/v2.0/introspect"
6464
private const val SIGN_IN_CHALLENGE_ENDPOINT_SUFFIX = "/oauth2/v2.0/challenge"
6565
private const val SIGN_IN_TOKEN_ENDPOINT_SUFFIX = "/oauth2/v2.0/token"
66+
private const val JIT_INTROSPECT_ENDPOINT_SUFFIX = "/register/v1.0/introspect"
67+
private const val JIT_CHALLENGE_ENDPOINT_SUFFIX = "/register/v1.0/challenge"
68+
private const val JIT_CONTINUE_ENDPOINT_SUFFIX = "/register/v1.0/continue"
6669
}
6770

6871
override fun getAuthorityUrl(): URL {
@@ -217,6 +220,42 @@ class NativeAuthOAuth2Configuration(
217220
)
218221
}
219222

223+
/**
224+
* Get the endpoint to be used for making a register/v1.0/introspect request.
225+
*
226+
* @return URL the endpoint
227+
*/
228+
fun getJITIntrospectEndpoint(): URL {
229+
return getEndpointUrlFromRootAndTenantAndSuffix(
230+
root = getAuthorityUrl(),
231+
endpointSuffix = JIT_INTROSPECT_ENDPOINT_SUFFIX
232+
)
233+
}
234+
235+
/**
236+
* Get the endpoint to be used for making a register/v1.0/challenge request.
237+
*
238+
* @return URL the endpoint
239+
*/
240+
fun getJITChallengeEndpoint(): URL {
241+
return getEndpointUrlFromRootAndTenantAndSuffix(
242+
root = getAuthorityUrl(),
243+
endpointSuffix = JIT_CHALLENGE_ENDPOINT_SUFFIX
244+
)
245+
}
246+
247+
/**
248+
* Get the endpoint to be used for making a register/v1.0/continue request.
249+
*
250+
* @return URL the endpoint
251+
*/
252+
fun getJITContinueEndpoint(): URL {
253+
return getEndpointUrlFromRootAndTenantAndSuffix(
254+
root = getAuthorityUrl(),
255+
endpointSuffix = JIT_CONTINUE_ENDPOINT_SUFFIX
256+
)
257+
}
258+
220259
private fun getEndpointUrlFromRootAndTenantAndSuffix(root: URL, endpointSuffix: String): URL {
221260
return try {
222261
if (BuildValues.getDC().isNotEmpty()) {

common4j/src/main/com/microsoft/identity/common/java/nativeauth/providers/NativeAuthRequestProvider.kt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpS
3636
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpSubmitPasswordCommandParameters
3737
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignUpSubmitUserAttributesCommandParameters
3838
import com.microsoft.identity.common.java.nativeauth.commands.parameters.SignInStartCommandParameters
39+
import com.microsoft.identity.common.java.nativeauth.providers.requests.jit.JITChallengeRequest
40+
import com.microsoft.identity.common.java.nativeauth.providers.requests.jit.JITContinueRequest
41+
import com.microsoft.identity.common.java.nativeauth.providers.requests.jit.JITIntrospectRequest
3942
import com.microsoft.identity.common.java.net.HttpConstants
4043
import com.microsoft.identity.common.java.nativeauth.providers.requests.resetpassword.ResetPasswordChallengeRequest
4144
import com.microsoft.identity.common.java.nativeauth.providers.requests.resetpassword.ResetPasswordContinueRequest
@@ -71,6 +74,9 @@ class NativeAuthRequestProvider(private val config: NativeAuthOAuth2Configuratio
7174
private val resetPasswordContinueEndpoint = config.getResetPasswordContinueEndpoint().toString()
7275
private val resetPasswordSubmitEndpoint = config.getResetPasswordSubmitEndpoint().toString()
7376
private val resetPasswordPollCompletionEndpoint = config.getResetPasswordPollCompletionEndpoint().toString()
77+
private val jitIntrospectEndpoint = config.getJITIntrospectEndpoint().toString()
78+
private val jitChallengeEndpoint = config.getJITChallengeEndpoint().toString()
79+
private val jitContinueEndpoint = config.getJITContinueEndpoint().toString()
7480

7581
//region /oauth/v2.0/initiate
7682
/**
@@ -348,6 +354,58 @@ class NativeAuthRequestProvider(private val config: NativeAuthOAuth2Configuratio
348354
}
349355
//endregion
350356

357+
//region /register/introspect
358+
internal fun createJITIntrospectRequest(
359+
continuationToken: String,
360+
correlationId: String
361+
): JITIntrospectRequest {
362+
return JITIntrospectRequest.create(
363+
continuationToken = continuationToken,
364+
clientId = config.clientId,
365+
requestUrl = jitIntrospectEndpoint,
366+
headers = getRequestHeaders(correlationId)
367+
)
368+
}
369+
//endregion
370+
371+
//region /register/challenge
372+
internal fun createJITChallengeRequest(
373+
continuationToken: String,
374+
challengeType: String,
375+
challengeTarget: String,
376+
challengeChannel: String,
377+
correlationId: String
378+
): JITChallengeRequest {
379+
return JITChallengeRequest.create(
380+
continuationToken = continuationToken,
381+
challengeType = challengeType,
382+
challengeTarget = challengeTarget,
383+
challengeChannel = challengeChannel,
384+
clientId = config.clientId,
385+
requestUrl = jitChallengeEndpoint,
386+
headers = getRequestHeaders(correlationId)
387+
)
388+
}
389+
//endregion
390+
391+
//region /register/continue
392+
internal fun createJITContinueRequest(
393+
continuationToken: String,
394+
grantType: String,
395+
code: String,
396+
correlationId: String
397+
): JITContinueRequest {
398+
return JITContinueRequest.create(
399+
continuationToken = continuationToken,
400+
grantType = grantType,
401+
oob = code,
402+
clientId = config.clientId,
403+
requestUrl = jitContinueEndpoint,
404+
headers = getRequestHeaders(correlationId)
405+
)
406+
}
407+
//endregion
408+
351409
//region helpers
352410
private fun getRequestHeaders(correlationId: String): Map<String, String?> {
353411
val headers: MutableMap<String, String?> = TreeMap()

0 commit comments

Comments
 (0)