Skip to content

Commit 84ef390

Browse files
author
Brian Melton-Grace
authored
Add metadata to TSL result payload (#1152)
* Update submodule pointer * Update submodule pointer * Update submodule to pickup enum -> string conversion * Wiring up external/internal calls * Update javadoc * Update submodule for merge
1 parent 7c233ea commit 84ef390

File tree

4 files changed

+101
-7
lines changed

4 files changed

+101
-7
lines changed

common

Submodule common updated 53 files

msal/src/main/java/com/microsoft/identity/client/ITokenShare.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@
2424

2525
import com.microsoft.identity.client.exception.MsalClientException;
2626
import com.microsoft.identity.common.adal.internal.tokensharing.ITokenShareInternal;
27+
import com.microsoft.identity.common.adal.internal.tokensharing.ITokenShareResultInternal;
2728

2829
/**
2930
* Interface defining necessary methods for TokenShareLibrary (TSL) integration.
3031
*/
3132
public interface ITokenShare extends ITokenShareInternal {
3233

34+
/**
35+
* {@inheritDoc}
36+
*/
37+
@Override
38+
TokenShareResult getOrgIdFamilyRefreshTokenWithMetadata(String identifier) throws MsalClientException;
39+
3340
/**
3441
* {@inheritDoc}
3542
*/
@@ -42,6 +49,12 @@ public interface ITokenShare extends ITokenShareInternal {
4249
@Override
4350
void saveOrgIdFamilyRefreshToken(String ssoStateSerializerBlob) throws MsalClientException;
4451

52+
/**
53+
* {@inheritDoc}
54+
*/
55+
@Override
56+
TokenShareResult getMsaFamilyRefreshTokenWithMetadata(String identifier) throws MsalClientException;
57+
4558
/**
4659
* {@inheritDoc}
4760
*/

msal/src/main/java/com/microsoft/identity/client/PublicClientApplication.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@
4848
import com.microsoft.identity.client.helper.BrokerHelperActivity;
4949
import com.microsoft.identity.client.internal.AsyncResult;
5050
import com.microsoft.identity.client.internal.CommandParametersAdapter;
51-
import com.microsoft.identity.common.internal.controllers.LocalMSALController;
5251
import com.microsoft.identity.client.internal.controllers.MSALControllerFactory;
5352
import com.microsoft.identity.client.internal.controllers.MsalExceptionAdapter;
5453
import com.microsoft.identity.common.adal.internal.cache.IStorageHelper;
5554
import com.microsoft.identity.common.adal.internal.cache.StorageHelper;
55+
import com.microsoft.identity.common.adal.internal.tokensharing.ITokenShareResultInternal;
5656
import com.microsoft.identity.common.adal.internal.tokensharing.TokenShareUtility;
5757
import com.microsoft.identity.common.exception.BaseException;
5858
import com.microsoft.identity.common.exception.ClientException;
@@ -68,8 +68,8 @@
6868
import com.microsoft.identity.common.internal.cache.SchemaUtil;
6969
import com.microsoft.identity.common.internal.cache.SharedPreferencesFileManager;
7070
import com.microsoft.identity.common.internal.commands.CommandCallback;
71-
import com.microsoft.identity.common.internal.commands.DeviceCodeFlowCommandCallback;
7271
import com.microsoft.identity.common.internal.commands.DeviceCodeFlowCommand;
72+
import com.microsoft.identity.common.internal.commands.DeviceCodeFlowCommandCallback;
7373
import com.microsoft.identity.common.internal.commands.GetDeviceModeCommand;
7474
import com.microsoft.identity.common.internal.commands.InteractiveTokenCommand;
7575
import com.microsoft.identity.common.internal.commands.SilentTokenCommand;
@@ -80,6 +80,7 @@
8080
import com.microsoft.identity.common.internal.controllers.BaseController;
8181
import com.microsoft.identity.common.internal.controllers.CommandDispatcher;
8282
import com.microsoft.identity.common.internal.controllers.ExceptionAdapter;
83+
import com.microsoft.identity.common.internal.controllers.LocalMSALController;
8384
import com.microsoft.identity.common.internal.dto.AccountRecord;
8485
import com.microsoft.identity.common.internal.eststelemetry.PublicApiId;
8586
import com.microsoft.identity.common.internal.logging.Logger;
@@ -1132,12 +1133,13 @@ private void setupTelemetry(@NonNull final Context context,
11321133
}
11331134

11341135
@Override
1135-
public String getOrgIdFamilyRefreshToken(@NonNull final String identifier) throws MsalClientException {
1136+
public TokenShareResult getOrgIdFamilyRefreshTokenWithMetadata(@NonNull final String identifier) throws MsalClientException {
11361137
validateNonNullArgument(identifier, "identifier");
11371138
validateBrokerNotInUse();
11381139

11391140
try {
1140-
return mTokenShareUtility.getOrgIdFamilyRefreshToken(identifier);
1141+
final ITokenShareResultInternal resultInternal = mTokenShareUtility.getOrgIdFamilyRefreshTokenWithMetadata(identifier);
1142+
return new TokenShareResult(resultInternal);
11411143
} catch (final Exception e) {
11421144
throw new MsalClientException(
11431145
TOKEN_CACHE_ITEM_NOT_FOUND,
@@ -1147,6 +1149,11 @@ public String getOrgIdFamilyRefreshToken(@NonNull final String identifier) throw
11471149
}
11481150
}
11491151

1152+
@Override
1153+
public String getOrgIdFamilyRefreshToken(@NonNull final String identifier) throws MsalClientException {
1154+
return getOrgIdFamilyRefreshTokenWithMetadata(identifier).getRefreshToken();
1155+
}
1156+
11501157
@Override
11511158
public void saveOrgIdFamilyRefreshToken(@NonNull final String ssoStateSerializerBlob) throws MsalClientException {
11521159
validateNonNullArgument(ssoStateSerializerBlob, "SsoStateSerializerBlob");
@@ -1164,12 +1171,13 @@ public void saveOrgIdFamilyRefreshToken(@NonNull final String ssoStateSerializer
11641171
}
11651172

11661173
@Override
1167-
public String getMsaFamilyRefreshToken(@NonNull final String identifier) throws MsalClientException {
1174+
public TokenShareResult getMsaFamilyRefreshTokenWithMetadata(@NonNull final String identifier) throws MsalClientException {
11681175
validateNonNullArgument(identifier, "identifier");
11691176
validateBrokerNotInUse();
11701177

11711178
try {
1172-
return mTokenShareUtility.getMsaFamilyRefreshToken(identifier);
1179+
final ITokenShareResultInternal resultInternal = mTokenShareUtility.getMsaFamilyRefreshTokenWithMetadata(identifier);
1180+
return new TokenShareResult(resultInternal);
11731181
} catch (final Exception e) {
11741182
throw new MsalClientException(
11751183
TOKEN_CACHE_ITEM_NOT_FOUND,
@@ -1179,6 +1187,11 @@ public String getMsaFamilyRefreshToken(@NonNull final String identifier) throws
11791187
}
11801188
}
11811189

1190+
@Override
1191+
public String getMsaFamilyRefreshToken(@NonNull final String identifier) throws MsalClientException {
1192+
return getMsaFamilyRefreshTokenWithMetadata(identifier).getRefreshToken();
1193+
}
1194+
11821195
@Override
11831196
public void saveMsaFamilyRefreshToken(@NonNull final String refreshToken) throws MsalClientException {
11841197
validateNonNullArgument(refreshToken, "refreshToken");
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// All rights reserved.
3+
//
4+
// This code is licensed under the MIT License.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files(the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions :
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
package com.microsoft.identity.client;
24+
25+
import androidx.annotation.NonNull;
26+
27+
import com.microsoft.identity.common.adal.internal.tokensharing.ITokenShareResultInternal;
28+
import com.microsoft.identity.common.adal.internal.tokensharing.TokenShareResultInternal;
29+
30+
/**
31+
* Refresh Token Related Metadata for consumption by TSL.
32+
*/
33+
public class TokenShareResult extends TokenShareResultInternal {
34+
35+
/**
36+
* The format of the refresh token in this result payload.
37+
*/
38+
public static class TokenShareExportFormat {
39+
40+
/**
41+
* Used for ORG_ID accounts. Legacy format used by ADAL.
42+
*/
43+
public static final String SSO_STATE_SERIALIZER_BLOB = TokenShareExportFormatInternal.SSO_STATE_SERIALIZER_BLOB;
44+
45+
/**
46+
* Raw RT String. Used by MSA format.
47+
*/
48+
public static final String RAW = TokenShareExportFormatInternal.RAW;
49+
}
50+
51+
TokenShareResult(@NonNull final ITokenShareResultInternal resultInternal) {
52+
super(
53+
resultInternal.getCacheRecord(),
54+
resultInternal.getRefreshToken(),
55+
resultInternal.getFormat()
56+
);
57+
}
58+
59+
/**
60+
* {@inheritDoc}
61+
*
62+
* @see TokenShareExportFormat
63+
*/
64+
@Override
65+
public String getFormat() {
66+
return super.getFormat();
67+
}
68+
}

0 commit comments

Comments
 (0)