-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathDeviceCodeFlowParameters.java
More file actions
166 lines (137 loc) · 5.83 KB
/
DeviceCodeFlowParameters.java
File metadata and controls
166 lines (137 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.microsoft.aad.msal4j;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import static com.microsoft.aad.msal4j.ParameterValidationUtils.validateNotNull;
/**
* Object containing parameters for device code flow. Can be used as parameter to
* {@link PublicClientApplication#acquireToken(DeviceCodeFlowParameters)}. For more details,
* see https://aka.ms/msal4j-device-code
*/
public class DeviceCodeFlowParameters implements IAcquireTokenParameters {
private Set<String> scopes;
private Consumer<DeviceCode> deviceCodeConsumer;
private ClaimsRequest claims;
private Map<String, String> extraHttpHeaders;
private Map<String, String> extraQueryParameters;
private String tenant;
private DeviceCodeFlowParameters(Set<String> scopes, Consumer<DeviceCode> deviceCodeConsumer, ClaimsRequest claims, Map<String, String> extraHttpHeaders, Map<String, String> extraQueryParameters, String tenant) {
this.scopes = scopes;
this.deviceCodeConsumer = deviceCodeConsumer;
this.claims = claims;
this.extraHttpHeaders = extraHttpHeaders;
this.extraQueryParameters = extraQueryParameters;
this.tenant = tenant;
}
private static DeviceCodeFlowParametersBuilder builder() {
return new DeviceCodeFlowParametersBuilder();
}
/**
* Builder for {@link DeviceCodeFlowParameters}
*
* @param scopes scopes application is requesting access to
* @param deviceCodeConsumer {@link Consumer} of {@link DeviceCode}
* @return builder that can be used to construct DeviceCodeFlowParameters
*/
public static DeviceCodeFlowParametersBuilder builder
(Set<String> scopes, Consumer<DeviceCode> deviceCodeConsumer) {
validateNotNull("scopes", scopes);
return builder()
.scopes(scopes)
.deviceCodeConsumer(deviceCodeConsumer);
}
public Set<String> scopes() {
return this.scopes;
}
public Consumer<DeviceCode> deviceCodeConsumer() {
return this.deviceCodeConsumer;
}
public ClaimsRequest claims() {
return this.claims;
}
public Map<String, String> extraHttpHeaders() {
return this.extraHttpHeaders;
}
/**
* @deprecated Not recommended for production scenarios. It will be removed in a future release, and the behavior may be replaced by a new API.
*/
@Deprecated
public Map<String, String> extraQueryParameters() {
return this.extraQueryParameters;
}
public String tenant() {
return this.tenant;
}
public static class DeviceCodeFlowParametersBuilder {
private Set<String> scopes;
private Consumer<DeviceCode> deviceCodeConsumer;
private ClaimsRequest claims;
private Map<String, String> extraHttpHeaders;
private Map<String, String> extraQueryParameters;
private String tenant;
DeviceCodeFlowParametersBuilder() {
}
/**
* Scopes to which the application is requesting access to.
* <p>
* Cannot be null.
*/
public DeviceCodeFlowParametersBuilder scopes(Set<String> scopes) {
validateNotNull("scopes", scopes);
this.scopes = scopes;
return this;
}
/**
* Receives the device code returned from the first step of Oauth2.0 device code flow. The
* {@link DeviceCode#verificationUri} and the {@link DeviceCode#userCode} should be shown
* to the end user.
* <p>
* For more details, see https://aka.ms/msal4j-device-code
* <p>
* Cannot be null.
*/
public DeviceCodeFlowParametersBuilder deviceCodeConsumer(Consumer<DeviceCode> deviceCodeConsumer) {
validateNotNull("deviceCodeConsumer", deviceCodeConsumer);
this.deviceCodeConsumer = deviceCodeConsumer;
return this;
}
/**
* Claims to be requested through the OIDC claims request parameter, allowing requests for standard and custom claims
*/
public DeviceCodeFlowParametersBuilder claims(ClaimsRequest claims) {
this.claims = claims;
return this;
}
/**
* Adds additional headers to the token request
*/
public DeviceCodeFlowParametersBuilder extraHttpHeaders(Map<String, String> extraHttpHeaders) {
this.extraHttpHeaders = extraHttpHeaders;
return this;
}
/**
* Adds additional query parameters to the token request
* @deprecated Not recommended for production scenarios. It will be removed in a future release, and the behavior may be replaced by a new API.
*/
@Deprecated
public DeviceCodeFlowParametersBuilder extraQueryParameters(Map<String, String> extraQueryParameters) {
this.extraQueryParameters = extraQueryParameters;
return this;
}
/**
* Overrides the tenant value in the authority URL for this request
*/
public DeviceCodeFlowParametersBuilder tenant(String tenant) {
this.tenant = tenant;
return this;
}
public DeviceCodeFlowParameters build() {
return new DeviceCodeFlowParameters(this.scopes, this.deviceCodeConsumer, this.claims, this.extraHttpHeaders, this.extraQueryParameters, this.tenant);
}
public String toString() {
return "DeviceCodeFlowParameters.DeviceCodeFlowParametersBuilder(scopes=" + this.scopes + ", deviceCodeConsumer=" + this.deviceCodeConsumer + ", claims=" + this.claims + ", extraHttpHeaders=" + this.extraHttpHeaders + ", extraQueryParameters=" + this.extraQueryParameters + ", tenant=" + this.tenant + ")";
}
}
}