Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SAS-based authentication #43448

Merged
merged 19 commits into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions sdk/maps/README.md
Original file line number Diff line number Diff line change
@@ -7,9 +7,13 @@ Microsoft Azure Maps provides developers from all industries with powerful geosp
## Getting started

To get started with a specific library, see the **README.md** file located in the library's project folder.
- [Azure Maps Search](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-search/README.md) contains Search APIs for querying addresses, nearby locations, geopolygons etc.
- [Azure Maps Route](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-route/README.md) contains Route APIs for calculating matrix of route summaries, returning routes between destinations, etc.
- [Azure Maps Geolocation](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-geolocation/README.md) contains Geolocation APIs for determining the country/region of an IP address, etc.
- [Azure Maps Render](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-render/README.md) contains Render APIs to request map tiles, metadata for tilesets, etc.
- [Azure Maps Route](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-route/README.md) contains Route APIs for calculating matrix of route summaries, returning routes between destinations, etc.
- [Azure Maps Search](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-search/README.md) contains Search APIs for querying addresses, nearby locations, geopolygons, etc.
- [Azure Maps Timezone](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-timezone/README.md) contains Timezone APIs for converting between UTC and local times based on geographic locations, etc.
- [Azure Maps Traffic](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-traffic/README.md) contains Traffic APIs for providing traffic flow and incident information to enhance navigation and routing applications, etc.
- [Azure Maps Weather](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/maps/azure-maps-weather/README.md) contains Weather APIs for retrieving current weather conditions, forecasts, and weather alerts, etc.

## Key concepts

@@ -20,9 +24,13 @@ For details on contributing to this repository, see the [contributing guide](htt
## Examples

For examples of each module please see:
- [Azure Maps Search Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-search/src/samples)
- [Azure Maps Route Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-route/src/samples)
- [Azure Maps Geolocation Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-geolocation/src/samples)
- [Azure Maps Render Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-render/src/samples)
- [Azure Maps Route Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-route/src/samples)
- [Azure Maps Search Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-search/src/samples)
- [Azure Maps Timezone Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-timezone/src/samples)
- [Azure Maps Traffic Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-traffic/src/samples)
- [Azure Maps Weather Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-weather/src/samples)

## Troubleshooting
When you interact with the Azure Maps Services, errors returned by the Maps service correspond to the same HTTP status codes returned for REST API requests.
@@ -32,11 +40,13 @@ For example, if you search with an invalid coordinate, a error is returned, indi
## Next steps

Several Azure Maps Java SDK samples are available to you in the SDK's GitHub repository.
- [Azure Maps Search Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-search/src/samples)
- [Azure Maps Route Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-route/src/samples)
)
- [Azure Maps Geolocation Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-geolocation/src/samples)
- [Azure Maps Render Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-render/src/samples)
)
- [Azure Maps Route Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-route/src/samples)
- [Azure Maps Search Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-search/src/samples)
- [Azure Maps Timezone Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-timezone/src/samples)
- [Azure Maps Traffic Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-traffic/src/samples)
- [Azure Maps Weather Samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-maps-weather/src/samples)

## Contributing

6 changes: 6 additions & 0 deletions sdk/maps/azure-maps-geolocation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.0.0-beta.3 (Unreleased)

### Features added

- Integrated support for SAS-based authentication

## 1.0.0-beta.2 (2024-11-08)

### Other Changes
8 changes: 6 additions & 2 deletions sdk/maps/azure-maps-geolocation/README.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@ Azure Management Libraries require a `TokenCredential` implementation for authen

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configure of following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
@@ -61,7 +63,9 @@ GeolocationClient client = new GeolocationClientBuilder()
.buildClient();
```

TThe sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.
The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

Original file line number Diff line number Diff line change
@@ -10,7 +10,9 @@
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.client.traits.AzureSasCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
@@ -28,6 +30,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.AzureSasCredentialPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
@@ -58,7 +61,8 @@
* <!-- end com.azure.maps.geolocation.sync.builder.ad.instantiation -->
*/
@ServiceClientBuilder(serviceClients = { GeolocationClient.class, GeolocationAsyncClient.class })
public final class GeolocationClientBuilder implements AzureKeyCredentialTrait<GeolocationClientBuilder>,
public final class GeolocationClientBuilder
implements AzureKeyCredentialTrait<GeolocationClientBuilder>, AzureSasCredentialTrait<GeolocationClientBuilder>,
TokenCredentialTrait<GeolocationClientBuilder>, HttpTrait<GeolocationClientBuilder>,
ConfigurationTrait<GeolocationClientBuilder>, EndpointTrait<GeolocationClientBuilder> {

@@ -98,6 +102,7 @@ public final class GeolocationClientBuilder implements AzureKeyCredentialTrait<G
// credentials
private AzureKeyCredential keyCredential;
private TokenCredential tokenCredential;
private AzureSasCredential sasCredential;

/**
* Default constructor for the builder class.
@@ -262,6 +267,19 @@ public GeolocationClientBuilder credential(AzureKeyCredential keyCredential) {
return this;
}

/**
* Sets the {@link AzureSasCredential} used to authenticate HTTP requests.
*
* @param sasCredential The {@link AzureSasCredential} used to authenticate HTTP requests.
* @return The updated {@link GeolocationClientBuilder} object.
* @throws NullPointerException If {@code sasCredential} is null.
*/
@Override
public GeolocationClientBuilder credential(AzureSasCredential sasCredential) {
this.sasCredential = Objects.requireNonNull(sasCredential, "'sasCredential' cannot be null.");
return this;
}

/**
* Sets retry options
*
@@ -339,6 +357,8 @@ private HttpPipeline createHttpPipeline() {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
} else if (keyCredential != null) {
policies.add(new AzureKeyCredentialPolicy(GEOLOCATION_SUBSCRIPTION_KEY, keyCredential));
} else if (sasCredential != null) {
policies.add(new AzureSasCredentialPolicy(sasCredential));
} else {
// Throw exception that credential and tokenCredential cannot be null
throw LOGGER.logExceptionAsError(
6 changes: 6 additions & 0 deletions sdk/maps/azure-maps-render/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 2.0.0-beta.2 (Unreleased)

### Features added

- Integrated support for SAS-based authentication

## 2.0.0-beta.1 (2024-11-08)

### Features Added
6 changes: 5 additions & 1 deletion sdk/maps/azure-maps-render/README.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@ Azure Maps Libraries require a `TokenCredential` implementation for authenticati

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configure of following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
@@ -66,6 +68,8 @@ MapsRenderClient client = builder.buildClient();

The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

## Key concepts
Original file line number Diff line number Diff line change
@@ -10,7 +10,9 @@
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.client.traits.AzureSasCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
@@ -28,6 +30,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.AzureSasCredentialPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
@@ -78,7 +81,8 @@
* <!-- end com.azure.maps.render.sync.builder.ad.instantiation -->
*/
@ServiceClientBuilder(serviceClients = { MapsRenderClient.class, MapsRenderAsyncClient.class })
public final class MapsRenderClientBuilder implements AzureKeyCredentialTrait<MapsRenderClientBuilder>,
public final class MapsRenderClientBuilder
implements AzureKeyCredentialTrait<MapsRenderClientBuilder>, AzureSasCredentialTrait<MapsRenderClientBuilder>,
TokenCredentialTrait<MapsRenderClientBuilder>, HttpTrait<MapsRenderClientBuilder>,
ConfigurationTrait<MapsRenderClientBuilder>, EndpointTrait<MapsRenderClientBuilder> {

@@ -142,6 +146,7 @@ public MapsRenderClientBuilder() {
// credentials
private AzureKeyCredential keyCredential;
private TokenCredential tokenCredential;
private AzureSasCredential sasCredential;

/**
* Sets the Azure Maps client id for use with Azure AD Authentication. This client id
@@ -297,6 +302,19 @@ public MapsRenderClientBuilder credential(AzureKeyCredential keyCredential) {
return this;
}

/**
* Sets the {@link AzureSasCredential} used to authenticate HTTP requests.
*
* @param sasCredential The {@link AzureSasCredential} used to authenticate HTTP requests.
* @return The updated {@link MapsRenderClientBuilder} object.
* @throws NullPointerException If {@code sasCredential} is null.
*/
@Override
public MapsRenderClientBuilder credential(AzureSasCredential sasCredential) {
this.sasCredential = Objects.requireNonNull(sasCredential, "'sasCredential' cannot be null.");
return this;
}

/**
* Builds an instance of RenderClientImpl with the provided parameters.
*
@@ -361,6 +379,8 @@ private HttpPipeline createHttpPipeline() {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
} else if (keyCredential != null) {
policies.add(new AzureKeyCredentialPolicy(RENDER_SUBSCRIPTION_KEY, keyCredential));
} else if (sasCredential != null) {
policies.add(new AzureSasCredentialPolicy(sasCredential));
} else {
// Throw exception that credential and tokenCredential cannot be null
throw LOGGER.logExceptionAsError(
6 changes: 6 additions & 0 deletions sdk/maps/azure-maps-route/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 1.0.0-beta.3 (Unreleased)

### Features added

- Integrated support for SAS-based authentication

## 1.0.0-beta.2 (2024-11-08)

### Other Changes
6 changes: 5 additions & 1 deletion sdk/maps/azure-maps-route/README.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@ Azure Maps Libraries require a `TokenCredential` implementation for authenticati

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configure of following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
@@ -66,6 +68,8 @@ MapsRouteAsyncClient client = builder.buildAsyncClient();

The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

## Key concepts
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.client.traits.AzureSasCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
@@ -27,6 +29,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.AzureSasCredentialPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
@@ -76,7 +79,8 @@
* <!-- end com.azure.maps.route.sync.builder.ad.instantiation -->
*/
@ServiceClientBuilder(serviceClients = { MapsRouteClient.class, MapsRouteAsyncClient.class })
public final class MapsRouteClientBuilder implements AzureKeyCredentialTrait<MapsRouteClientBuilder>,
public final class MapsRouteClientBuilder
implements AzureKeyCredentialTrait<MapsRouteClientBuilder>, AzureSasCredentialTrait<MapsRouteClientBuilder>,
TokenCredentialTrait<MapsRouteClientBuilder>, HttpTrait<MapsRouteClientBuilder>,
ConfigurationTrait<MapsRouteClientBuilder>, EndpointTrait<MapsRouteClientBuilder> {

@@ -109,6 +113,7 @@ public final class MapsRouteClientBuilder implements AzureKeyCredentialTrait<Map
// credentials
private AzureKeyCredential keyCredential;
private TokenCredential tokenCredential;
private AzureSasCredential sasCredential;

/**
* Default constructor for the builder class.
@@ -276,6 +281,19 @@ public MapsRouteClientBuilder credential(AzureKeyCredential keyCredential) {
return this;
}

/**
* Sets the {@link AzureSasCredential} used to authenticate HTTP requests.
*
* @param sasCredential The {@link AzureSasCredential} used to authenticate HTTP requests.
* @return The updated {@link MapsRouteClientBuilder} object.
* @throws NullPointerException If {@code sasCredential} is null.
*/
@Override
public MapsRouteClientBuilder credential(AzureSasCredential sasCredential) {
this.sasCredential = Objects.requireNonNull(sasCredential, "'sasCredential' cannot be null.");
return this;
}

/**
* Sets retry options
*
@@ -353,6 +371,8 @@ private HttpPipeline createHttpPipeline() {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
} else if (keyCredential != null) {
policies.add(new AzureKeyCredentialPolicy(MAPS_SUBSCRIPTION_KEY, keyCredential));
} else if (sasCredential != null) {
policies.add(new AzureSasCredentialPolicy(sasCredential));
} else {
// Throw exception that credential and tokenCredential cannot be null
throw LOGGER.logExceptionAsError(
8 changes: 2 additions & 6 deletions sdk/maps/azure-maps-search/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,13 +2,9 @@

## 2.0.0-beta.2 (Unreleased)

### Features Added

### Breaking Changes

### Bugs Fixed
### Features added

### Other Changes
- Integrated support for SAS-based authentication

## 2.0.0-beta.1 (2024-12-17)

6 changes: 5 additions & 1 deletion sdk/maps/azure-maps-search/README.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@ Azure Maps Libraries require a `TokenCredential` implementation for authenticati

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configuration of the following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
@@ -66,6 +68,8 @@ MapsSearchClient client = builder.buildClient();

The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

## Key concepts
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.client.traits.AzureSasCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
@@ -27,6 +29,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.AzureSasCredentialPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
@@ -60,7 +63,8 @@
* <!-- end com.azure.maps.search.sync.builder.ad.instantiation -->
*/
@ServiceClientBuilder(serviceClients = { MapsSearchClient.class, MapsSearchAsyncClient.class })
public final class MapsSearchClientBuilder implements AzureKeyCredentialTrait<MapsSearchClientBuilder>,
public final class MapsSearchClientBuilder
implements AzureKeyCredentialTrait<MapsSearchClientBuilder>, AzureSasCredentialTrait<MapsSearchClientBuilder>,
TokenCredentialTrait<MapsSearchClientBuilder>, HttpTrait<MapsSearchClientBuilder>,
ConfigurationTrait<MapsSearchClientBuilder>, EndpointTrait<MapsSearchClientBuilder> {

@@ -94,6 +98,7 @@ public final class MapsSearchClientBuilder implements AzureKeyCredentialTrait<Ma
// credentials
private AzureKeyCredential keyCredential;
private TokenCredential tokenCredential;
private AzureSasCredential sasCredential;

/**
* Default constructor for the builder class.
@@ -262,6 +267,19 @@ public MapsSearchClientBuilder credential(AzureKeyCredential keyCredential) {
return this;
}

/**
* Sets the {@link AzureSasCredential} used to authenticate HTTP requests.
*
* @param sasCredential The {@link AzureSasCredential} used to authenticate HTTP requests.
* @return The updated {@link MapsSearchClientBuilder} object.
* @throws NullPointerException If {@code sasCredential} is null.
*/
@Override
public MapsSearchClientBuilder credential(AzureSasCredential sasCredential) {
this.sasCredential = Objects.requireNonNull(sasCredential, "'sasCredential' cannot be null.");
return this;
}

/**
* Sets retry options
* @param retryOptions the retry options for the client
@@ -338,6 +356,8 @@ private HttpPipeline createHttpPipeline() {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
} else if (keyCredential != null) {
policies.add(new AzureKeyCredentialPolicy(MAPS_SUBSCRIPTION_KEY, keyCredential));
} else if (sasCredential != null) {
policies.add(new AzureSasCredentialPolicy(sasCredential));
} else {
// Throw exception that credential and tokenCredential cannot be null
throw LOGGER.logExceptionAsError(
2 changes: 2 additions & 0 deletions sdk/maps/azure-maps-timezone/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@

### Features Added

- Integrated support for SAS-based authentication

### Breaking Changes

### Bugs Fixed
6 changes: 5 additions & 1 deletion sdk/maps/azure-maps-timezone/README.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@ Azure Management Libraries require a `TokenCredential` implementation for authen

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configure of following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
@@ -63,6 +65,8 @@ TimeZoneClient client = new TimeZoneClientBuilder()

The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

## Key concepts
Original file line number Diff line number Diff line change
@@ -10,7 +10,9 @@
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.client.traits.AzureSasCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
@@ -28,6 +30,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.AzureSasCredentialPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
@@ -43,24 +46,10 @@

/**
* Builder class used to instantiate both synchronous and asynchronous {@link TimeZoneClient} clients.
* <p><b>Example usage</b></p>
* Creating a sync client using a {@link AzureKeyCredential}:
* <!-- src_embed com.azure.maps.timezone.sync.builder.key.instantiation -->
* <pre>
* &#47;&#47; Authenticates using subscription key
* AzureKeyCredential keyCredential = new AzureKeyCredential&#40;System.getenv&#40;&quot;SUBSCRIPTION_KEY&quot;&#41;&#41;;
*
* &#47;&#47; Creates a client
* TimeZoneClient client = new TimeZoneClientBuilder&#40;&#41;
* .credential&#40;keyCredential&#41;
* .timezoneClientId&#40;System.getenv&#40;&quot;MAPS_CLIENT_ID&quot;&#41;&#41;
* .buildClient&#40;&#41;;
* </pre>
* <!-- end com.azure.maps.timezone.sync.builder.ad.instantiation -->
*/
@ServiceClientBuilder(serviceClients = { TimeZoneClient.class, TimeZoneAsyncClient.class })
public final class TimeZoneClientBuilder
implements AzureKeyCredentialTrait<TimeZoneClientBuilder>, TokenCredentialTrait<TimeZoneClientBuilder>,
public final class TimeZoneClientBuilder implements AzureKeyCredentialTrait<TimeZoneClientBuilder>,
AzureSasCredentialTrait<TimeZoneClientBuilder>, TokenCredentialTrait<TimeZoneClientBuilder>,
HttpTrait<TimeZoneClientBuilder>, ConfigurationTrait<TimeZoneClientBuilder>, EndpointTrait<TimeZoneClientBuilder> {

// constants
@@ -105,6 +94,7 @@ public final class TimeZoneClientBuilder
// credentials
private AzureKeyCredential keyCredential;
private TokenCredential tokenCredential;
private AzureSasCredential sasCredential;

/** Default constructor for the builder class; Create an instance of the TimeZoneClientBuilder. */
public TimeZoneClientBuilder() {
@@ -269,6 +259,19 @@ public TimeZoneClientBuilder credential(AzureKeyCredential keyCredential) {
return this;
}

/**
* Sets the {@link AzureSasCredential} used to authenticate HTTP requests.
*
* @param sasCredential The {@link AzureSasCredential} used to authenticate HTTP requests.
* @return The updated {@link TimeZoneClientBuilder} object.
* @throws NullPointerException If {@code sasCredential} is null.
*/
@Override
public TimeZoneClientBuilder credential(AzureSasCredential sasCredential) {
this.sasCredential = Objects.requireNonNull(sasCredential, "'sasCredential' cannot be null.");
return this;
}

/**
* Sets retry options
* @param retryOptions the retry options for the client
@@ -345,6 +348,8 @@ private HttpPipeline createHttpPipeline() {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
} else if (keyCredential != null) {
policies.add(new AzureKeyCredentialPolicy(MAPS_SUBSCRIPTION_KEY, keyCredential));
} else if (sasCredential != null) {
policies.add(new AzureSasCredentialPolicy(sasCredential));
} else {
// Throw exception that credential and tokenCredential cannot be null
throw LOGGER.logExceptionAsError(
2 changes: 2 additions & 0 deletions sdk/maps/azure-maps-weather/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@

### Features Added

- Integrated support for SAS-based authentication

### Breaking Changes

### Bugs Fixed
6 changes: 5 additions & 1 deletion sdk/maps/azure-maps-weather/README.md
Original file line number Diff line number Diff line change
@@ -39,7 +39,9 @@ Azure Maps Libraries require a `TokenCredential` implementation for authenticati

### Authentication

By default, Azure Active Directory token authentication depends on correct configure of following environment variables.
There are 3 ways to authenticate the client: Shared key authentication, Microsoft Entra ID authentication, and shared access signature (SAS) authentication.

By default, Microsoft Entra ID token authentication depends on correct configuration of the following environment variables.

- `AZURE_CLIENT_ID` for Azure client ID.
- `AZURE_TENANT_ID` for Azure tenant ID.
@@ -63,6 +65,8 @@ WeatherClient client = new WeatherClientBuilder()

The sample code assumes global Azure. Please change `AzureEnvironment.AZURE` variable if otherwise.

For SAS-based authentication, please refer to [AccountsListSasSamples.java][https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/maps/azure-resourcemanager-maps/src/samples/java/com/azure/resourcemanager/maps/generated/AccountsListSasSamples.java].

See [Authentication][authenticate] for more options.

## Key concepts
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@
import com.azure.core.client.traits.EndpointTrait;
import com.azure.core.client.traits.HttpTrait;
import com.azure.core.client.traits.TokenCredentialTrait;
import com.azure.core.client.traits.AzureSasCredentialTrait;
import com.azure.core.credential.AzureKeyCredential;
import com.azure.core.credential.AzureSasCredential;
import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpHeaderName;
@@ -27,6 +29,7 @@
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.http.policy.RetryPolicy;
import com.azure.core.http.policy.UserAgentPolicy;
import com.azure.core.http.policy.AzureSasCredentialPolicy;
import com.azure.core.util.ClientOptions;
import com.azure.core.util.Configuration;
import com.azure.core.util.CoreUtils;
@@ -42,46 +45,18 @@

/**
* Builder class used to instantiate both synchronous and asynchronous {@link WeatherClient} clients.
* <p><b>Example usage</b></p>
* Creating a sync client using a {@link AzureKeyCredential}:
* <!-- src_embed com.azure.maps.weather.sync.builder.key.instantiation -->
* <pre>
* &#47;&#47; Authenticates using subscription key
* AzureKeyCredential keyCredential = new AzureKeyCredential&#40;System.getenv&#40;&quot;SUBSCRIPTION_KEY&quot;&#41;&#41;;
*
* &#47;&#47; Creates a client
* WeatherClient client = new WeatherClientBuilder&#40;&#41;
* .credential&#40;keyCredential&#41;
* .weatherClientId&#40;System.getenv&#40;&quot;MAPS_CLIENT_ID&quot;&#41;&#41;
* .buildClient&#40;&#41;;
* </pre>
* <!-- end com.azure.maps.weather.sync.builder.key.instantiation -->
* Creating a sync client using a {@link TokenCredential}:
* <!-- src_embed com.azure.maps.weather.sync.builder.ad.instantiation -->
* <pre>
* &#47;&#47; Authenticates using Azure AD building a default credential
* &#47;&#47; This will look for AZURE_CLIENT_ID, AZURE_TENANT_ID, and AZURE_CLIENT_SECRET env variables
* DefaultAzureCredential tokenCredential = new DefaultAzureCredentialBuilder&#40;&#41;.build&#40;&#41;;
*
* &#47;&#47; Creates a client
* WeatherClient client = new WeatherClientBuilder&#40;&#41;
* .credential&#40;tokenCredential&#41;
* .weatherClientId&#40;System.getenv&#40;&quot;MAPS_CLIENT_ID&quot;&#41;&#41;
* .buildClient&#40;&#41;;
* </pre>
* <!-- end com.azure.maps.weather.sync.builder.ad.instantiation -->
*/
@ServiceClientBuilder(serviceClients = { WeatherClient.class, WeatherAsyncClient.class })
public final class WeatherClientBuilder
implements AzureKeyCredentialTrait<WeatherClientBuilder>, TokenCredentialTrait<WeatherClientBuilder>,
public final class WeatherClientBuilder implements AzureKeyCredentialTrait<WeatherClientBuilder>,
AzureSasCredentialTrait<WeatherClientBuilder>, TokenCredentialTrait<WeatherClientBuilder>,
HttpTrait<WeatherClientBuilder>, ConfigurationTrait<WeatherClientBuilder>, EndpointTrait<WeatherClientBuilder> {

// constants
private static final ClientLogger LOGGER = new ClientLogger(WeatherClientBuilder.class);
private static final String SDK_NAME = "name";
private static final String SDK_VERSION = "version";
private static final HttpHeaderName X_MS_CLIENT_ID = HttpHeaderName.fromString("x-ms-client-id");
private static final Map<String, String> PROPERTIES = CoreUtils.getProperties("azure-maps-timezone.properties");
private static final Map<String, String> PROPERTIES = CoreUtils.getProperties("azure-maps-weather.properties");

// subscription-key
static final String MAPS_SUBSCRIPTION_KEY = "subscription-key";
@@ -104,6 +79,7 @@ public final class WeatherClientBuilder
// credentials
private AzureKeyCredential keyCredential;
private TokenCredential tokenCredential;
private AzureSasCredential sasCredential;

/**
* Default constructor for the builder class.
@@ -265,6 +241,18 @@ public WeatherClientBuilder credential(AzureKeyCredential keyCredential) {
return this;
}

/**
* Sets the {@link AzureSasCredential} used to authenticate HTTP requests.
*
* @param sasCredential The {@link AzureSasCredential} used to authenticate HTTP requests.
* @return The updated {@link WeatherClientBuilder} object.
* @throws NullPointerException If {@code sasCredential} is null.
*/
public WeatherClientBuilder credential(AzureSasCredential sasCredential) {
this.sasCredential = Objects.requireNonNull(sasCredential, "'sasCredential' cannot be null.");
return this;
}

/**
* Sets retry options
* @param retryOptions the retry options for the client
@@ -341,6 +329,8 @@ private HttpPipeline createHttpPipeline() {
policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES));
} else if (keyCredential != null) {
policies.add(new AzureKeyCredentialPolicy(MAPS_SUBSCRIPTION_KEY, keyCredential));
} else if (sasCredential != null) {
policies.add(new AzureSasCredentialPolicy(sasCredential));
} else {
// Throw exception that credential and tokenCredential cannot be null
throw LOGGER.logExceptionAsError(