Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Update auth code URL builder (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
Avery-Dunn authored Jun 30, 2020
1 parent 911ee83 commit e8b53fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion msal-java-webapp-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.4.0</version>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,23 +156,22 @@ void sendAuthRedirect(HttpServletRequest httpRequest, HttpServletResponse httpRe
String getAuthorizationCodeUrl(String claims, String scope, String registeredRedirectURL, String state, String nonce)
throws UnsupportedEncodingException {

String urlEncodedScopes = scope == null ?
URLEncoder.encode("openid offline_access profile", "UTF-8") :
URLEncoder.encode("openid offline_access profile" + " " + scope, "UTF-8");


String authorizationCodeUrl = authority + "oauth2/v2.0/authorize?" +
"response_type=code&" +
"response_mode=query&" +
"redirect_uri=" + URLEncoder.encode(registeredRedirectURL, "UTF-8") +
"&client_id=" + clientId +
"&scope=" + urlEncodedScopes +
(StringUtils.isEmpty(claims) ? "" : "&claims=" + claims) +
"&prompt=select_account" +
"&state=" + state
+ "&nonce=" + nonce;

return authorizationCodeUrl;
String urlEncodedScopes = scope == null ? "" : URLEncoder.encode(scope, "UTF-8");

PublicClientApplication pca = PublicClientApplication.builder(clientId).build();

AuthorizationRequestUrlParameters parameters =
AuthorizationRequestUrlParameters
.builder(registeredRedirectURL,
Collections.singleton(urlEncodedScopes))
.responseMode(ResponseMode.QUERY)
.prompt(Prompt.SELECT_ACCOUNT)
.state(state)
.nonce(nonce)
.claimsChallenge(claims)
.build();

return pca.getAuthorizationRequestUrl(parameters).toString();
}

private IAuthenticationResult getAuthResultByAuthCode(
Expand Down

0 comments on commit e8b53fa

Please sign in to comment.