Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/kiota-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.0
Choose a base ref
...
head repository: microsoft/kiota-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.1
Choose a head ref
  • 4 commits
  • 5 files changed
  • 2 contributors

Commits on Feb 9, 2024

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5551fc5 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    288879e View commit details
  3. Update CHANGELOG.md

    baywet authored Feb 9, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9dd4bba View commit details
  4. Merge pull request #1072 from microsoft/fix/https-localhost

    Allow https on localhost URLs
    baywet authored Feb 9, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5689ba4 View commit details
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [1.0.1] - 2024-02-09

### Changed

- Allow authentication for localhost HTTP urls

## [1.0.0] - 2024-02-07

### Changed
1 change: 1 addition & 0 deletions components/authentication/azure/gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies {
// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.2'
testImplementation 'org.mockito:mockito-inline:5.2.0'


Original file line number Diff line number Diff line change
@@ -16,7 +16,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;

@@ -26,6 +28,8 @@ public class AzureIdentityAccessTokenProvider implements AccessTokenProvider {
private final List<String> _scopes;
private final AllowedHostsValidator _hostValidator;
private final ObservabilityOptions _observabilityOptions;
private static final HashSet<String> localhostStrings =
new HashSet<>(Arrays.asList("localhost", "[::1]", "::1", "127.0.0.1"));

/**
* Creates a new instance of AzureIdentityAccessTokenProvider.
@@ -102,7 +106,7 @@ public AzureIdentityAccessTokenProvider(
span.setAttribute("com.microsoft.kiota.authentication.is_url_valid", false);
return "";
}
if (!uri.getScheme().equalsIgnoreCase("https")) {
if (!uri.getScheme().equalsIgnoreCase("https") && !isLocalhostUrl(uri.getHost())) {
span.setAttribute("com.microsoft.kiota.authentication.is_url_valid", false);
throw new IllegalArgumentException("Only https is supported");
}
@@ -146,4 +150,9 @@ public AzureIdentityAccessTokenProvider(
@Nonnull public AllowedHostsValidator getAllowedHostsValidator() {
return _hostValidator;
}

private static boolean isLocalhostUrl(@Nonnull String host) {
Objects.requireNonNull(host);
return localhostStrings.contains(host.toLowerCase(Locale.ROOT));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.microsoft.kiota.authentication;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenCredential;
import com.azure.core.credential.TokenRequestContext;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;

public class AzureIdentityAccessTokenProviderTest {

@ParameterizedTest
@ValueSource(
strings = {"http://localhost:80/me", "http://127.0.0.1/me", "http://[::1]:8080/me"})
void testLocalhostHttpUrlIsValid(String urlString) throws URISyntaxException {
var tokenCredential = mock(TokenCredential.class);
when(tokenCredential.getTokenSync(any(TokenRequestContext.class)))
.thenReturn(new AccessToken("token", null));
var accessTokenProvider = new AzureIdentityAccessTokenProvider(tokenCredential, null, "");
assertEquals(
"token",
accessTokenProvider.getAuthorizationToken(new URI(urlString), new HashMap<>()));
}

@ParameterizedTest
@ValueSource(strings = {"http://graph.microsoft.com/me"})
void testNonLocalhostHttpUrlIsInvalid(String urlString) {
var tokenCredential = mock(TokenCredential.class);
var accessTokenProvider = new AzureIdentityAccessTokenProvider(tokenCredential, null, "");
assertThrows(
IllegalArgumentException.class,
() ->
accessTokenProvider.getAuthorizationToken(
new URI(urlString), new HashMap<>()));
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ org.gradle.caching=true
mavenGroupId = com.microsoft.kiota
mavenMajorVersion = 1
mavenMinorVersion = 0
mavenPatchVersion = 0
mavenPatchVersion = 1
mavenArtifactSuffix =

#These values are used to run functional tests