Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private static final class SerializedNames {
final static String LOCAL_ACCOUNT_ID = "local_account_id";
final static String USERNAME = "username";
final static String EXTRA_QUERY_STRING_PARAMETER = "extra_query_param";
final static String EXTRA_TOKEN_BODY_PARAMETER = "extra_token_body_param";
final static String CORRELATION_ID = "correlation_id";
final static String PROMPT = "prompt";
final static String CLAIMS = "claims";
Expand Down Expand Up @@ -140,6 +141,13 @@ private static final class SerializedNames {
@SerializedName(SerializedNames.EXTRA_QUERY_STRING_PARAMETER)
private String mExtraQueryStringParameter;

/**
* Extra token body parameters for the request.
*/
@Nullable
@SerializedName(SerializedNames.EXTRA_TOKEN_BODY_PARAMETER)
private String mExtraTokenBodyParameter;

/**
* Extra options flags for the request.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import com.microsoft.identity.common.java.commands.parameters.DeviceCodeFlowCommandParameters;
import com.microsoft.identity.common.java.commands.parameters.GenerateShrCommandParameters;
import com.microsoft.identity.common.java.commands.parameters.GetAadDeviceIdCommandParameters;
import com.microsoft.identity.common.java.commands.parameters.IHasExtraTokenBodyParameters;
import com.microsoft.identity.common.java.commands.parameters.InteractiveTokenCommandParameters;
import com.microsoft.identity.common.java.commands.parameters.RemoveAccountCommandParameters;
import com.microsoft.identity.common.java.commands.parameters.ResourceAccountCommandParameters;
Expand Down Expand Up @@ -95,6 +96,8 @@ public BrokerRequest brokerRequestFromAcquireTokenParameters(@NonNull final Inte
: null;
final String extraOptions = parameters.getExtraOptions() != null ?
QueryParamsAdapter._toJson(parameters.getExtraOptions()) : null;
final String extraTokenBodyParameters = parameters.getExtraTokenBodyParameters() != null ?
QueryParamsAdapter._toJson(parameters.getExtraTokenBodyParameters()) : null;

final BrokerRequest.BrokerRequestBuilder brokerRequestBuilder = BrokerRequest.builder()
.authority(parameters.getAuthority().getAuthorityURL().toString())
Expand All @@ -106,6 +109,7 @@ public BrokerRequest brokerRequestFromAcquireTokenParameters(@NonNull final Inte
.userName(parameters.getLoginHint())
.extraQueryStringParameter(extraQueryStringParameter)
.extraOptions(extraOptions)
.extraTokenBodyParameter(extraTokenBodyParameters)
.prompt((OpenIdConnectPromptParameter.UNSET.name().equals(parameters.getPrompt().name())) ? null : parameters.getPrompt().name())
.claims(parameters.getClaimsRequestJson())
.forceRefresh(parameters.isForceRefresh())
Expand Down Expand Up @@ -178,7 +182,7 @@ public BrokerRequest brokerRequestFromSilentOperationParameters(@NonNull final S
final String extraOptions = parameters.getExtraOptions() != null ?
QueryParamsAdapter._toJson(parameters.getExtraOptions()) : null;

final BrokerRequest brokerRequest = BrokerRequest.builder()
final BrokerRequest.BrokerRequestBuilder brokerRequestBuilder = BrokerRequest.builder()
.authority(parameters.getAuthority().getAuthorityURL().toString())
.scope(TextUtils.join(" ", parameters.getScopes()))
.redirect(parameters.getRedirectUri())
Expand All @@ -205,10 +209,13 @@ public BrokerRequest brokerRequestFromSilentOperationParameters(@NonNull final S
.spanId(SpanExtension.current().getSpanContext().getSpanId())
.traceFlags(SpanExtension.current().getSpanContext().getTraceFlags().asByte())
.build()
)
.build();

return brokerRequest;
);
if (parameters instanceof IHasExtraTokenBodyParameters) {
final String extraTokenBodyParameters = ((IHasExtraTokenBodyParameters) parameters).getExtraTokenBodyParameters() != null ?
QueryParamsAdapter._toJson(((IHasExtraTokenBodyParameters) parameters).getExtraTokenBodyParameters()) : null;
brokerRequestBuilder.extraTokenBodyParameter(extraTokenBodyParameters);
}
return brokerRequestBuilder.build();
}

public @NonNull Bundle getRequestBundleForSsoToken(final @NonNull AcquirePrtSsoTokenCommandParameters parameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@
import com.microsoft.identity.common.java.request.BrokerRequestType;
import com.microsoft.identity.common.java.util.StringUtil;

import java.util.List;
import java.util.Map;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.experimental.SuperBuilder;

@Getter
@SuperBuilder(toBuilder = true)
@EqualsAndHashCode(callSuper = true)
public class BrokerSilentTokenCommandParameters extends SilentTokenCommandParameters implements IBrokerTokenCommandParameters {
public class BrokerSilentTokenCommandParameters
extends SilentTokenCommandParameters
implements IHasExtraTokenBodyParameters, IBrokerTokenCommandParameters {

@Expose
private final int callerUid;
Expand All @@ -55,6 +60,9 @@ public class BrokerSilentTokenCommandParameters extends SilentTokenCommandParame
@Expose
private final String negotiatedBrokerProtocolVersion;

// Only put in the token request body
private final List<Map.Entry<String, String>> extraTokenBodyParameters;

// If this flag is true, we will send the x-ms-PKeyAuth Header to the token endpoint.
// Note: this flag is transferred to a MicrosoftTokenRequest in BaseController.
@Expose
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.common.java.commands.parameters;

import java.util.List;
import java.util.Map;

/**
* Interface indicating that a class carries a set of string/string parameters that are intended
* to be merged into the OAuth2 token request body only.
*/
public interface IHasExtraTokenBodyParameters {

/**
* Get the {@link List} of pairs of String, String parameters.
*
* @return a list of pairs of String, String parameters - this may be null. There are no guarantees
* made with regards to the mutability of this structure, but it <strong>should not</strong> be
* mutated by the caller, and attempts to do so <strong>may</strong>may throw
* {@link UnsupportedOperationException} or result in undefined behavior.
*/
List<Map.Entry<String, String>> getExtraTokenBodyParameters();
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
@Getter
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
public class InteractiveTokenCommandParameters extends TokenCommandParameters {
public class InteractiveTokenCommandParameters extends TokenCommandParameters
implements IHasExtraTokenBodyParameters {

private final transient List<BrowserDescriptor> browserSafeList;

Expand Down Expand Up @@ -70,6 +71,9 @@ public class InteractiveTokenCommandParameters extends TokenCommandParameters {

private final List<Map.Entry<String, String>> extraQueryStringParameters;

// Only put in the token request body
private final List<Map.Entry<String, String>> extraTokenBodyParameters;

@Expose()
private final List<String> extraScopesToConsent;

Expand Down
Loading