3
3
4
4
package com .microsoft .aad .msal4j ;
5
5
6
- import lombok .*;
7
- import lombok .experimental .Accessors ;
8
-
9
6
import java .net .URI ;
10
7
import java .util .Map ;
11
8
import java .util .Set ;
12
9
13
10
import static com .microsoft .aad .msal4j .ParameterValidationUtils .validateNotBlank ;
11
+ import static com .microsoft .aad .msal4j .ParameterValidationUtils .validateNotNull ;
14
12
15
13
/**
16
14
* Object containing parameters for authorization code flow. Can be used as parameter to
17
15
* {@link PublicClientApplication#acquireToken(AuthorizationCodeParameters)} or to
18
16
* {@link ConfidentialClientApplication#acquireToken(AuthorizationCodeParameters)}
19
17
*/
20
- @ Builder
21
- @ Accessors (fluent = true )
22
- @ Getter
23
- @ AllArgsConstructor (access = AccessLevel .PRIVATE )
24
18
public class AuthorizationCodeParameters implements IAcquireTokenParameters {
25
19
26
- /**
27
- * Authorization code acquired in the first step of OAuth2.0 authorization code flow. For more
28
- * details, see https://aka.ms/msal4j-authorization-code-flow
29
- */
30
- @ NonNull
31
20
private String authorizationCode ;
32
21
33
- /**
34
- * Redirect URI registered in the Azure portal, and which was used in the first step of OAuth2.0
35
- * authorization code flow. For more details, see https://aka.ms/msal4j-authorization-code-flow
36
- */
37
- @ NonNull
38
22
private URI redirectUri ;
39
23
40
- /**
41
- * Scopes to which the application is requesting access
42
- */
43
24
private Set <String > scopes ;
44
25
45
- /**
46
- * Claims to be requested through the OIDC claims request parameter, allowing requests for standard and custom claims
47
- */
48
26
private ClaimsRequest claims ;
49
27
50
- /**
51
- * Code verifier used for PKCE. For more details, see https://tools.ietf.org/html/rfc7636
52
- */
53
28
private String codeVerifier ;
54
29
55
- /**
56
- * Adds additional headers to the token request
57
- */
58
30
private Map <String , String > extraHttpHeaders ;
59
31
60
- /**
61
- * Adds additional query parameters to the token request
62
- */
63
32
private Map <String , String > extraQueryParameters ;
64
33
65
- /**
66
- * Overrides the tenant value in the authority URL for this request
67
- */
68
34
private String tenant ;
69
35
36
+ private AuthorizationCodeParameters (String authorizationCode , URI redirectUri ,
37
+ Set <String > scopes , ClaimsRequest claims ,
38
+ String codeVerifier , Map <String , String > extraHttpHeaders ,
39
+ Map <String , String > extraQueryParameters , String tenant ) {
40
+ this .authorizationCode = authorizationCode ;
41
+ this .redirectUri = redirectUri ;
42
+ this .scopes = scopes ;
43
+ this .claims = claims ;
44
+ this .codeVerifier = codeVerifier ;
45
+ this .extraHttpHeaders = extraHttpHeaders ;
46
+ this .extraQueryParameters = extraQueryParameters ;
47
+ this .tenant = tenant ;
48
+ }
49
+
70
50
private static AuthorizationCodeParametersBuilder builder () {
71
51
72
52
return new AuthorizationCodeParametersBuilder ();
@@ -87,4 +67,132 @@ public static AuthorizationCodeParametersBuilder builder(String authorizationCod
87
67
.authorizationCode (authorizationCode )
88
68
.redirectUri (redirectUri );
89
69
}
70
+
71
+ public String authorizationCode () {
72
+ return this .authorizationCode ;
73
+ }
74
+
75
+ public URI redirectUri () {
76
+ return this .redirectUri ;
77
+ }
78
+
79
+ public Set <String > scopes () {
80
+ return this .scopes ;
81
+ }
82
+
83
+ public ClaimsRequest claims () {
84
+ return this .claims ;
85
+ }
86
+
87
+ public String codeVerifier () {
88
+ return this .codeVerifier ;
89
+ }
90
+
91
+ public Map <String , String > extraHttpHeaders () {
92
+ return this .extraHttpHeaders ;
93
+ }
94
+
95
+ public Map <String , String > extraQueryParameters () {
96
+ return this .extraQueryParameters ;
97
+ }
98
+
99
+ public String tenant () {
100
+ return this .tenant ;
101
+ }
102
+
103
+ public static class AuthorizationCodeParametersBuilder {
104
+ private String authorizationCode ;
105
+ private URI redirectUri ;
106
+ private Set <String > scopes ;
107
+ private ClaimsRequest claims ;
108
+ private String codeVerifier ;
109
+ private Map <String , String > extraHttpHeaders ;
110
+ private Map <String , String > extraQueryParameters ;
111
+ private String tenant ;
112
+
113
+ AuthorizationCodeParametersBuilder () {
114
+ }
115
+
116
+ /**
117
+ * Authorization code acquired in the first step of OAuth2.0 authorization code flow. For more
118
+ * details, see https://aka.ms/msal4j-authorization-code-flow
119
+ * <p>
120
+ * Cannot be null.
121
+ */
122
+ public AuthorizationCodeParametersBuilder authorizationCode (String authorizationCode ) {
123
+ validateNotNull ("authorizationCode" , authorizationCode );
124
+
125
+ this .authorizationCode = authorizationCode ;
126
+ return this ;
127
+ }
128
+
129
+ /**
130
+ * Redirect URI registered in the Azure portal, and which was used in the first step of OAuth2.0
131
+ * authorization code flow. For more details, see https://aka.ms/msal4j-authorization-code-flow
132
+ * <p>
133
+ * Cannot be null.
134
+ */
135
+ public AuthorizationCodeParametersBuilder redirectUri (URI redirectUri ) {
136
+ validateNotNull ("redirectUri" , redirectUri );
137
+
138
+ this .redirectUri = redirectUri ;
139
+ return this ;
140
+ }
141
+
142
+ /**
143
+ * Scopes to which the application is requesting access
144
+ */
145
+ public AuthorizationCodeParametersBuilder scopes (Set <String > scopes ) {
146
+ this .scopes = scopes ;
147
+ return this ;
148
+ }
149
+
150
+ /**
151
+ * Claims to be requested through the OIDC claims request parameter, allowing requests for standard and custom claims
152
+ */
153
+ public AuthorizationCodeParametersBuilder claims (ClaimsRequest claims ) {
154
+ this .claims = claims ;
155
+ return this ;
156
+ }
157
+
158
+ /**
159
+ * Code verifier used for PKCE. For more details, see https://tools.ietf.org/html/rfc7636
160
+ */
161
+ public AuthorizationCodeParametersBuilder codeVerifier (String codeVerifier ) {
162
+ this .codeVerifier = codeVerifier ;
163
+ return this ;
164
+ }
165
+
166
+ /**
167
+ * Adds additional headers to the token request
168
+ */
169
+ public AuthorizationCodeParametersBuilder extraHttpHeaders (Map <String , String > extraHttpHeaders ) {
170
+ this .extraHttpHeaders = extraHttpHeaders ;
171
+ return this ;
172
+ }
173
+
174
+ /**
175
+ * Adds additional query parameters to the token request
176
+ */
177
+ public AuthorizationCodeParametersBuilder extraQueryParameters (Map <String , String > extraQueryParameters ) {
178
+ this .extraQueryParameters = extraQueryParameters ;
179
+ return this ;
180
+ }
181
+
182
+ /**
183
+ * Overrides the tenant value in the authority URL for this request
184
+ */
185
+ public AuthorizationCodeParametersBuilder tenant (String tenant ) {
186
+ this .tenant = tenant ;
187
+ return this ;
188
+ }
189
+
190
+ public AuthorizationCodeParameters build () {
191
+ return new AuthorizationCodeParameters (this .authorizationCode , this .redirectUri , this .scopes , this .claims , this .codeVerifier , this .extraHttpHeaders , this .extraQueryParameters , this .tenant );
192
+ }
193
+
194
+ public String toString () {
195
+ return "AuthorizationCodeParameters.AuthorizationCodeParametersBuilder(authorizationCode=" + this .authorizationCode + ", redirectUri=" + this .redirectUri + ", scopes=" + this .scopes + ", claims=" + this .claims + ", codeVerifier=" + this .codeVerifier + ", extraHttpHeaders=" + this .extraHttpHeaders + ", extraQueryParameters=" + this .extraQueryParameters + ", tenant=" + this .tenant + ")" ;
196
+ }
197
+ }
90
198
}
0 commit comments