-
Notifications
You must be signed in to change notification settings - Fork 493
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(service-client): Add constructors to accept aad and sas tokens for d…
…igital twins client. (#1790)
- Loading branch information
Showing
8 changed files
with
176 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
iothub/service/src/DigitalTwin/Authentication/DigitalTwinSasCredential.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Azure; | ||
using Microsoft.Azure.Devices.Authentication; | ||
|
||
namespace Microsoft.Azure.Devices.DigitalTwin.Authentication | ||
{ | ||
/// <summary> | ||
/// Allows authentication to the API using a Shared Access Key provided by custom implementation. | ||
/// The PnP client is auto generated from swagger and needs to implement a specific class to pass to the protocol layer | ||
/// unlike the rest of the clients which are hand-written. So, this implementation for authentication is specific to digital twin (Pnp). | ||
/// </summary> | ||
internal class DigitalTwinSasCredential : DigitalTwinServiceClientCredentials | ||
{ | ||
private AzureSasCredential _credential; | ||
|
||
public DigitalTwinSasCredential(AzureSasCredential credential) | ||
{ | ||
_credential = credential; | ||
} | ||
|
||
public override string GetAuthorizationHeader() | ||
{ | ||
return _credential.Signature; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
iothub/service/src/DigitalTwin/Authentication/DigitalTwinTokenCredential.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading; | ||
using Azure.Core; | ||
using Microsoft.Azure.Devices.Authentication; | ||
|
||
namespace Microsoft.Azure.Devices.DigitalTwin.Authentication | ||
{ | ||
/// <summary> | ||
/// Allows authentication to the API using a JWT token generated for Azure active directory. | ||
/// The PnP client is auto generated from swagger and needs to implement a specific class to pass to the protocol layer | ||
/// unlike the rest of the clients which are hand-written. so, this implementation for authentication is specific to digital twin (Pnp). | ||
/// </summary> | ||
internal class DigitalTwinTokenCredential : DigitalTwinServiceClientCredentials | ||
{ | ||
private TokenCredential _credential; | ||
|
||
public DigitalTwinTokenCredential(TokenCredential credential) | ||
{ | ||
_credential = credential; | ||
} | ||
|
||
public override string GetAuthorizationHeader() | ||
{ | ||
AccessToken token = _credential.GetToken(new TokenRequestContext(), new CancellationToken()); | ||
return $"Bearer {token.Token}"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters