Skip to content

Commit

Permalink
Merge pull request #185 from AzureAD/dev
Browse files Browse the repository at this point in the history
1.4.0 Release
  • Loading branch information
sangonzal authored Feb 21, 2020
2 parents 4fbf681 + 102061f commit 1cc8866
Show file tree
Hide file tree
Showing 102 changed files with 3,063 additions and 1,032 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Quick links:
The library supports the following Java environments:
- Java 8 (or higher)

Current version - 1.3.0
Current version - 1.4.0

You can find the changes for each version in the [change log](https://github.com/AzureAD/microsoft-authentication-library-for-java/blob/master/changelog.txt).

Expand All @@ -28,13 +28,13 @@ Find [the latest package in the Maven repository](https://mvnrepository.com/arti
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>
```
### Gradle

```
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.3.0'
compile group: 'com.microsoft.azure', name: 'msal4j', version: '1.4.0'
```

## Usage
Expand Down
Empty file removed RELEASES.md
Empty file.
1 change: 1 addition & 0 deletions bnd.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Export-Package: com.microsoft.aad.msal4j
8 changes: 8 additions & 0 deletions build/credscan-exclude.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
{
"placeholder": "ClientPassword",
"_justification" : "credential used for testing. not associated with any tenant"
},
{
"placeholder": "B2C_CONFIDENTIAL_CLIENT_APP_SECRET",
"_justification" : "Not a credential, just the identifier of the secret exposed by test lab API"
},
{
"placeholder": "MSIDLABB2C-MSAapp-AppSecret",
"_justification" : "Not a credential, just the identifier of the secret exposed by test lab API"
}
]
}
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 1.4.0
=============
- Added acquire token interactive API, using system default browser
- Added authorization code url builder
- Added OSGi support via bnd-maven-plugin
- Added server-side telemetry support

Version 1.3.0
=============
- Added option to pass in AAD instance discovery data
Expand Down
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
<packaging>jar</packaging>
<name>msal4j</name>
<description>
Expand Down Expand Up @@ -162,6 +162,7 @@
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
Expand Down Expand Up @@ -249,6 +250,18 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>4.3.1</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.aad.msal4j;

import labapi.B2CProvider;
import labapi.FederationProvider;
import labapi.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.Collections;

public class AcquireTokenInteractiveIT extends SeleniumTest {

private final static Logger LOG = LoggerFactory.getLogger(AuthorizationCodeIT.class);

@Test
public void acquireTokenInteractive_ManagedUser(){
User user = labUserProvider.getDefaultUser();
assertAcquireTokenAAD(user);
}

@Test
public void acquireTokenInteractive_ADFSv2019_OnPrem(){
User user = labUserProvider.getOnPremAdfsUser(FederationProvider.ADFS_2019);
assertAcquireTokenADFS2019(user);
}

@Test
public void acquireTokenInteractive_ADFSv2019_Federated(){
User user = labUserProvider.getFederatedAdfsUser(FederationProvider.ADFS_2019);
assertAcquireTokenAAD(user);
}

@Test
public void acquireTokenInteractive_ADFSv4_Federated(){
User user = labUserProvider.getFederatedAdfsUser(FederationProvider.ADFS_4);
assertAcquireTokenAAD(user);
}

@Test
public void acquireTokenInteractive_ADFSv3_Federated(){
User user = labUserProvider.getFederatedAdfsUser(FederationProvider.ADFS_3);
assertAcquireTokenAAD(user);
}

@Test
public void acquireTokenInteractive_ADFSv2_Federated(){
User user = labUserProvider.getFederatedAdfsUser(FederationProvider.ADFS_2);
assertAcquireTokenAAD(user);
}

@Test
public void acquireTokenWithAuthorizationCode_B2C_Local(){
User user = labUserProvider.getB2cUser(B2CProvider.LOCAL);
assertAcquireTokenB2C(user);
}

private void assertAcquireTokenAAD(User user){

PublicClientApplication pca;
try {
pca = PublicClientApplication.builder(
user.getAppId()).
authority(TestConstants.ORGANIZATIONS_AUTHORITY).
build();
} catch(MalformedURLException ex){
throw new RuntimeException(ex.getMessage());
}

IAuthenticationResult result = acquireTokenInteractive(
user,
pca,
TestConstants.GRAPH_DEFAULT_SCOPE);

Assert.assertNotNull(result);
Assert.assertNotNull(result.accessToken());
Assert.assertNotNull(result.idToken());
Assert.assertEquals(user.getUpn(), result.account().username());
}

private void assertAcquireTokenADFS2019(User user){
PublicClientApplication pca;
try {
pca = PublicClientApplication.builder(
TestConstants.ADFS_APP_ID).
authority(TestConstants.ADFS_AUTHORITY).
build();
} catch(MalformedURLException ex){
throw new RuntimeException(ex.getMessage());
}

IAuthenticationResult result = acquireTokenInteractive(user, pca, TestConstants.ADFS_SCOPE);

Assert.assertNotNull(result);
Assert.assertNotNull(result.accessToken());
Assert.assertNotNull(result.idToken());
Assert.assertEquals(user.getUpn(), result.account().username());
}

private void assertAcquireTokenB2C(User user){

PublicClientApplication pca;
try {
pca = PublicClientApplication.builder(
user.getAppId()).
b2cAuthority(TestConstants.B2C_AUTHORITY_SIGN_IN).
build();
} catch(MalformedURLException ex){
throw new RuntimeException(ex.getMessage());
}

IAuthenticationResult result = acquireTokenInteractive(user, pca, user.getAppId());
Assert.assertNotNull(result);
Assert.assertNotNull(result.accessToken());
Assert.assertNotNull(result.idToken());
}

private IAuthenticationResult acquireTokenInteractive(
User user,
PublicClientApplication pca,
String scope){

IAuthenticationResult result;
try {
URI url = new URI("http://localhost:8080");

SystemBrowserOptions browserOptions =
SystemBrowserOptions
.builder()
.openBrowserAction(new SeleniumOpenBrowserAction(user, pca))
.build();

InteractiveRequestParameters parameters = InteractiveRequestParameters
.builder(url)
.scopes(Collections.singleton(scope))
.systemBrowserOptions(browserOptions)
.build();

result = pca.acquireToken(parameters).get();

} catch(Exception e){
LOG.error("Error acquiring token with authCode: " + e.getMessage());
throw new RuntimeException("Error acquiring token with authCode: " + e.getMessage());
}
return result;
}

class SeleniumOpenBrowserAction implements OpenBrowserAction {

private User user;
private PublicClientApplication pca;

SeleniumOpenBrowserAction(User user, PublicClientApplication pca){
this.user = user;
this.pca = pca;
}

public void openBrowser(URL url){
seleniumDriver.navigate().to(url);
runSeleniumAutomatedLogin(user, pca);
}
}
}
Loading

0 comments on commit 1cc8866

Please sign in to comment.