Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.0.0-beta.3 (Unreleased)
- Allow the STS endpoint to be customized.
- Changed constructors to align with guidance.

## 1.0.0-beta.2 (2021-02-16)
- Reflect minor REST API improvements.
Expand Down
23 changes: 7 additions & 16 deletions sdk/mixedreality/Azure.MixedReality.RemoteRendering/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Install-Package Azure.MixedReality.RemoteRendering -AllowPrereleaseVersions
From .NET CLI

```dotnetcli
dotnet add package Azure.MixedReality.RemoteRendering --version 1.0.0-beta.1
dotnet add package Azure.MixedReality.RemoteRendering --version 1.0.0-beta.1
```

Add a package reference:
Expand All @@ -43,7 +43,6 @@ You will need an [Azure subscription](https://azure.microsoft.com/free/) and an
### Authenticate the client

Constructing a remote rendering client requires an authenticated account, and a remote rendering endpoint.
A RemoteRenderingAccount object is constructed from an accountId and an account domain.
For an account created in the eastus region, the account domain will have the form "eastus.mixedreality.azure.com".
There are several different forms of authentication:

Expand All @@ -66,42 +65,37 @@ An example is `https://remoterendering.eastus2.mixedreality.azure.com`.

> NOTE: For converting assets, it is preferable to pick a region close to the storage containing the assets.

> NOTE: For rendering, it is strongly recommended that you pick the closest region to the devices using the service.
> NOTE: For rendering, it is strongly recommended that you pick the closest region to the devices using the service.
> The time taken to communicate with the server impacts the quality of the experience.

#### Authenticating with account key authentication

Use the `AccountKeyCredential` object to use an account identifier and account key to authenticate:

```csharp Snippet:CreateAClient
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);
AzureKeyCredential accountKeyCredential = new AzureKeyCredential(accountKey);

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, accountKeyCredential);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, accountKeyCredential);
```

#### Authenticating with an AAD client secret

Use the `ClientSecretCredential` object to perform client secret authentication.

```csharp Snippet:CreateAClientWithAAD
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);

TokenCredential credential = new ClientSecretCredential(tenantId, clientId, clientSecret, new TokenCredentialOptions
{
AuthorityHost = new Uri($"https://login.microsoftonline.com/{tenantId}")
});

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, credential);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, credential);
```

#### Authenticating a user using device code authentication

Use the `DeviceCodeCredential` object to perform device code authentication.

```csharp Snippet:CreateAClientWithDeviceCode
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);

Task deviceCodeCallback(DeviceCodeInfo deviceCodeInfo, CancellationToken cancellationToken)
{
Debug.WriteLine(deviceCodeInfo.Message);
Expand All @@ -114,7 +108,7 @@ TokenCredential credential = new DeviceCodeCredential(deviceCodeCallback, tenant
AuthorityHost = new Uri($"https://login.microsoftonline.com/{tenantId}"),
});

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, credential);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, credential);
```

See [here](https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Device-Code-Flow) for more
Expand All @@ -126,10 +120,9 @@ Use the `DefaultAzureCredential` object with `includeInteractiveCredentials: tru
flow:

```csharp Snippet:CreateAClientWithAzureCredential
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);
TokenCredential credential = new DefaultAzureCredential(includeInteractiveCredentials: true);

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, credential);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, credential);
```

#### Authenticating with a static access token
Expand All @@ -139,15 +132,13 @@ You can pass a Mixed Reality access token as an `AccessToken` previously retriev
to be used with a Mixed Reality client library:

```csharp Snippet:CreateAClientWithStaticAccessToken
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);

// GetMixedRealityAccessTokenFromWebService is a hypothetical method that retrieves
// a Mixed Reality access token from a web service. The web service would use the
// MixedRealityStsClient and credentials to obtain an access token to be returned
// to the client.
AccessToken accessToken = GetMixedRealityAccessTokenFromWebService();

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, accessToken);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, accessToken);
```

## Key concepts
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,54 @@ public class RemoteRenderingClient
/// Initializes a new instance of the <see cref="RemoteRenderingClient" /> class.
/// </summary>
/// <param name="remoteRenderingEndpoint">The rendering service endpoint. This determines the region in which the rendering VM is created.</param>
/// <param name="account">The Azure Remote Rendering account details.</param>
/// <param name="accessToken">An access token used to access the specified Azure Remote Rendering account.</param>
/// <param name="options">The options.</param>
public RemoteRenderingClient(Uri remoteRenderingEndpoint, RemoteRenderingAccount account, AccessToken accessToken, RemoteRenderingClientOptions options = null)
: this(remoteRenderingEndpoint, account, new StaticAccessTokenCredential(accessToken), options) { }
/// <param name="accountId">The Azure Remote Rendering account identifier.</param>
/// <param name="accountDomain">The Azure Remote Rendering account domain.</param>
/// <param name="keyCredential">The Azure Remote Rendering account primary or secondary key credential.</param>
public RemoteRenderingClient(Uri remoteRenderingEndpoint, Guid accountId, string accountDomain, AzureKeyCredential keyCredential)
: this(remoteRenderingEndpoint, accountId, accountDomain, new MixedRealityAccountKeyCredential(accountId, keyCredential), null) { }

/// <summary>
/// Initializes a new instance of the <see cref="RemoteRenderingClient" /> class.
/// </summary>
/// <param name="remoteRenderingEndpoint">The rendering service endpoint. This determines the region in which the rendering VM is created.</param>
/// <param name="account">The Azure Remote Rendering account details.</param>
/// <param name="accountId">The Azure Remote Rendering account identifier.</param>
/// <param name="accountDomain">The Azure Remote Rendering account domain.</param>
/// <param name="keyCredential">The Azure Remote Rendering account primary or secondary key credential.</param>
/// <param name="options">The options.</param>
public RemoteRenderingClient(Uri remoteRenderingEndpoint, RemoteRenderingAccount account, AzureKeyCredential keyCredential, RemoteRenderingClientOptions options = null)
: this(remoteRenderingEndpoint, account, new MixedRealityAccountKeyCredential(account.AccountId, keyCredential), options) { }
public RemoteRenderingClient(Uri remoteRenderingEndpoint, Guid accountId, string accountDomain, AzureKeyCredential keyCredential, RemoteRenderingClientOptions options)
: this(remoteRenderingEndpoint, accountId, accountDomain, new MixedRealityAccountKeyCredential(accountId, keyCredential), options) { }

/// <summary>
/// Initializes a new instance of the <see cref="RemoteRenderingClient" /> class.
/// </summary>
/// <param name="remoteRenderingEndpoint">The rendering service endpoint. This determines the region in which the rendering VM is created.</param>
/// <param name="accountId">The Azure Remote Rendering account identifier.</param>
/// <param name="accountDomain">The Azure Remote Rendering account domain.</param>
/// <param name="accessToken">An access token used to access the specified Azure Remote Rendering account.</param>
/// <param name="options">The options.</param>
public RemoteRenderingClient(Uri remoteRenderingEndpoint, Guid accountId, string accountDomain, AccessToken accessToken, RemoteRenderingClientOptions options = null)
: this(remoteRenderingEndpoint, accountId, accountDomain, new StaticAccessTokenCredential(accessToken), options) { }

/// <summary>
/// Initializes a new instance of the <see cref="RemoteRenderingClient" /> class.
/// </summary>
/// <param name="remoteRenderingEndpoint">The rendering service endpoint. This determines the region in which the rendering VM is created.</param>
/// <param name="account">The Azure Remote Rendering account details.</param>
/// <param name="accountId">The Azure Remote Rendering account identifier.</param>
/// <param name="accountDomain">The Azure Remote Rendering account domain.</param>
/// <param name="credential">The credential used to access the Mixed Reality service.</param>
/// <param name="options">The options.</param>
public RemoteRenderingClient(Uri remoteRenderingEndpoint, RemoteRenderingAccount account, TokenCredential credential, RemoteRenderingClientOptions options = null)
public RemoteRenderingClient(Uri remoteRenderingEndpoint, Guid accountId, string accountDomain, TokenCredential credential, RemoteRenderingClientOptions options = null)
{
Argument.AssertNotNull(account, nameof(account));
Argument.AssertNotDefault(ref accountId, nameof(accountId));
Argument.AssertNotNullOrWhiteSpace(accountDomain, nameof(accountDomain));
Argument.AssertNotNull(credential, nameof(credential));

options ??= new RemoteRenderingClientOptions();

Uri authenticationEndpoint = options.AuthenticationEndpoint ?? AuthenticationEndpoint.ConstructFromDomain(account.AccountDomain);
TokenCredential mrTokenCredential = MixedRealityTokenCredential.GetMixedRealityCredential(account.AccountId, authenticationEndpoint, credential);
Uri authenticationEndpoint = options.AuthenticationEndpoint ?? AuthenticationEndpoint.ConstructFromDomain(accountDomain);
TokenCredential mrTokenCredential = MixedRealityTokenCredential.GetMixedRealityCredential(accountId, authenticationEndpoint, credential);

_accountId = account.AccountId;
_accountId = accountId;
_clientDiagnostics = new ClientDiagnostics(options);
_pipeline = HttpPipelineBuilder.Build(options, new BearerTokenAuthenticationPolicy(mrTokenCredential, GetDefaultScope(remoteRenderingEndpoint)));
_restClient = new RemoteRenderingRestClient(_clientDiagnostics, _pipeline, remoteRenderingEndpoint.ToString(), options.Version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ public void TestFailedSessionRequest()

private RemoteRenderingClient GetClient()
{
RemoteRenderingAccount account = new RemoteRenderingAccount(new Guid(TestEnvironment.AccountId), TestEnvironment.AccountDomain);
Guid accountId = new Guid(TestEnvironment.AccountId);
string accountDomain = TestEnvironment.AccountDomain;
Uri serviceEndpoint = new Uri(TestEnvironment.ServiceEndpoint);

var options = InstrumentClientOptions(new RemoteRenderingClientOptions());
Expand All @@ -199,12 +200,12 @@ private RemoteRenderingClient GetClient()
if (Mode != RecordedTestMode.Playback)
{
AzureKeyCredential accountKeyCredential = new AzureKeyCredential(TestEnvironment.AccountKey);
client = new RemoteRenderingClient(serviceEndpoint, account, accountKeyCredential, options);
client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, accountKeyCredential, options);
}
else
{
AccessToken artificialToken = new AccessToken("TestToken", DateTimeOffset.MaxValue);
client = new RemoteRenderingClient(serviceEndpoint, account, artificialToken, options);
client = new RemoteRenderingClient(serviceEndpoint, accountId, accountDomain, artificialToken, options);
}
return InstrumentClient(client);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ private RemoteRenderingClient GetClient()
string accountKey = TestEnvironment.AccountKey;
Uri remoteRenderingEndpoint = new Uri(TestEnvironment.ServiceEndpoint);

RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);
AzureKeyCredential accountKeyCredential = new AzureKeyCredential(accountKey);

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, accountKeyCredential);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, accountKeyCredential);
return client;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ private RemoteRenderingClient GetClientWithAccountKey()
Uri remoteRenderingEndpoint = new Uri(TestEnvironment.ServiceEndpoint);

#region Snippet:CreateAClient
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);
AzureKeyCredential accountKeyCredential = new AzureKeyCredential(accountKey);

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, accountKeyCredential);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, accountKeyCredential);
#endregion Snippet:CreateAClient
return client;
}
Expand Down Expand Up @@ -146,14 +145,13 @@ private RemoteRenderingClient GetClientWithAAD()
Uri remoteRenderingEndpoint = new Uri(TestEnvironment.ServiceEndpoint);

#region Snippet:CreateAClientWithAAD
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);

TokenCredential credential = new ClientSecretCredential(tenantId, clientId, clientSecret, new TokenCredentialOptions
{
AuthorityHost = new Uri($"https://login.microsoftonline.com/{tenantId}")
});

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, credential);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, credential);
#endregion Snippet:CreateAClientWithAAD
return client;
}
Expand All @@ -167,7 +165,6 @@ private RemoteRenderingClient GetClientWithDeviceCode()
Uri remoteRenderingEndpoint = new Uri(TestEnvironment.ServiceEndpoint);

#region Snippet:CreateAClientWithDeviceCode
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);

Task deviceCodeCallback(DeviceCodeInfo deviceCodeInfo, CancellationToken cancellationToken)
{
Expand All @@ -180,7 +177,7 @@ Task deviceCodeCallback(DeviceCodeInfo deviceCodeInfo, CancellationToken cancell
AuthorityHost = new Uri($"https://login.microsoftonline.com/{tenantId}"),
});

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, credential);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, credential);
#endregion Snippet:CreateAClientWithDeviceCode
return client;
}
Expand All @@ -192,10 +189,10 @@ private RemoteRenderingClient GetClientWithDefaultAzureCredential()
Uri remoteRenderingEndpoint = new Uri(TestEnvironment.ServiceEndpoint);

#region Snippet:CreateAClientWithAzureCredential
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);

TokenCredential credential = new DefaultAzureCredential(includeInteractiveCredentials: true);

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, credential);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, credential);
#endregion Snippet:CreateAClientWithAzureCredential

return client;
Expand All @@ -213,15 +210,14 @@ private RemoteRenderingClient GetClientWithStaticAccessToken()
Uri remoteRenderingEndpoint = new Uri(TestEnvironment.ServiceEndpoint);

#region Snippet:CreateAClientWithStaticAccessToken
RemoteRenderingAccount account = new RemoteRenderingAccount(accountId, accountDomain);

// GetMixedRealityAccessTokenFromWebService is a hypothetical method that retrieves
// a Mixed Reality access token from a web service. The web service would use the
// MixedRealityStsClient and credentials to obtain an access token to be returned
// to the client.
AccessToken accessToken = GetMixedRealityAccessTokenFromWebService();

RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, account, accessToken);
RemoteRenderingClient client = new RemoteRenderingClient(remoteRenderingEndpoint, accountId, accountDomain, accessToken);
#endregion Snippet:CreateAClientWithStaticAccessToken

return client;
Expand Down