33
44package com .microsoft .aad .msal4j ;
55
6- import lombok .*;
7- import lombok .experimental .Accessors ;
8-
96import java .net .URI ;
107import java .util .Map ;
118import java .util .Set ;
129
1310import static com .microsoft .aad .msal4j .ParameterValidationUtils .validateNotBlank ;
11+ import static com .microsoft .aad .msal4j .ParameterValidationUtils .validateNotNull ;
1412
1513/**
1614 * Object containing parameters for authorization code flow. Can be used as parameter to
1715 * {@link PublicClientApplication#acquireToken(AuthorizationCodeParameters)} or to
1816 * {@link ConfidentialClientApplication#acquireToken(AuthorizationCodeParameters)}
1917 */
20- @ Builder
21- @ Accessors (fluent = true )
22- @ Getter
23- @ AllArgsConstructor (access = AccessLevel .PRIVATE )
2418public class AuthorizationCodeParameters implements IAcquireTokenParameters {
2519
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
3120 private String authorizationCode ;
3221
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
3822 private URI redirectUri ;
3923
40- /**
41- * Scopes to which the application is requesting access
42- */
4324 private Set <String > scopes ;
4425
45- /**
46- * Claims to be requested through the OIDC claims request parameter, allowing requests for standard and custom claims
47- */
4826 private ClaimsRequest claims ;
4927
50- /**
51- * Code verifier used for PKCE. For more details, see https://tools.ietf.org/html/rfc7636
52- */
5328 private String codeVerifier ;
5429
55- /**
56- * Adds additional headers to the token request
57- */
5830 private Map <String , String > extraHttpHeaders ;
5931
60- /**
61- * Adds additional query parameters to the token request
62- */
6332 private Map <String , String > extraQueryParameters ;
6433
65- /**
66- * Overrides the tenant value in the authority URL for this request
67- */
6834 private String tenant ;
6935
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+
7050 private static AuthorizationCodeParametersBuilder builder () {
7151
7252 return new AuthorizationCodeParametersBuilder ();
@@ -87,4 +67,132 @@ public static AuthorizationCodeParametersBuilder builder(String authorizationCod
8767 .authorizationCode (authorizationCode )
8868 .redirectUri (redirectUri );
8969 }
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+ }
90198}
0 commit comments