Skip to content

Commit 23ffb90

Browse files
authored
3rd party auth (Azure#48440)
1 parent cbd4df9 commit 23ffb90

12 files changed

+687
-3
lines changed

sdk/core/Azure.Core.Experimental/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
- Added the following types for 3rd-party Authentication support: `AuthenticationTokenProvider`, `GetTokenOptions`, `AccessToken`, and `OAuth2BearerTokenAuthenticationPolicy`.
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.net461.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,46 @@ public ProvisionableTemplateAttribute(string resourceName) { }
120120
public string ResourceName { get { throw null; } }
121121
}
122122
}
123+
namespace System.ClientModel
124+
{
125+
public partial class AccessToken
126+
{
127+
public AccessToken(string tokenValue, string tokenType, System.DateTimeOffset expiresOn, System.DateTimeOffset? refreshOn = default(System.DateTimeOffset?)) { }
128+
public System.DateTimeOffset ExpiresOn { get { throw null; } protected set { } }
129+
public System.DateTimeOffset? RefreshOn { get { throw null; } protected set { } }
130+
public string TokenType { get { throw null; } protected set { } }
131+
public string TokenValue { get { throw null; } protected set { } }
132+
}
133+
public abstract partial class RefreshableToken : System.ClientModel.AccessToken
134+
{
135+
public RefreshableToken(string tokenValue, string tokenType, System.DateTimeOffset expiresOn, System.DateTimeOffset? refreshOn = default(System.DateTimeOffset?)) : base (default(string), default(string), default(System.DateTimeOffset), default(System.DateTimeOffset?)) { }
136+
public abstract System.Threading.Tasks.Task RefreshAsync(System.Threading.CancellationToken cancellationToken);
137+
}
138+
}
139+
namespace System.ClientModel.Auth
140+
{
141+
public partial class OAuth2BearerTokenAuthenticationPolicy : System.ClientModel.Primitives.PipelinePolicy
142+
{
143+
public OAuth2BearerTokenAuthenticationPolicy(System.ClientModel.Auth.TokenProvider tokenProvider, System.Collections.Generic.IEnumerable<System.Collections.Generic.IReadOnlyDictionary<string, object>> contexts) { }
144+
public override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { }
145+
public override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { throw null; }
146+
}
147+
public partial class TokenFlowProperties
148+
{
149+
public const string AuthorizationUrlPropertyName = "authorizationUrl";
150+
public const string RefreshUrlPropertyName = "refreshUrl";
151+
public const string ScopesPropertyName = "scopes";
152+
public const string TokenUrlPropertyName = "tokenUrl";
153+
public TokenFlowProperties(string[] scopes, System.Collections.Generic.IReadOnlyDictionary<string, object> properties) { }
154+
public System.Collections.Generic.IReadOnlyDictionary<string, object> Properties { get { throw null; } }
155+
public string[] Scopes { get { throw null; } }
156+
public System.ClientModel.Auth.TokenFlowProperties WithAdditionalScopes(string[] additionalScopes) { throw null; }
157+
}
158+
public abstract partial class TokenProvider
159+
{
160+
protected TokenProvider() { }
161+
public abstract System.ClientModel.Auth.TokenFlowProperties? CreateContext(System.Collections.Generic.IReadOnlyDictionary<string, object> properties);
162+
public abstract System.ClientModel.AccessToken GetToken(System.ClientModel.Auth.TokenFlowProperties properties, System.Threading.CancellationToken cancellationToken);
163+
public abstract System.Threading.Tasks.ValueTask<System.ClientModel.AccessToken> GetTokenAsync(System.ClientModel.Auth.TokenFlowProperties properties, System.Threading.CancellationToken cancellationToken);
164+
}
165+
}

sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.net462.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,41 @@ public ProvisionableTemplateAttribute(string resourceName) { }
120120
public string ResourceName { get { throw null; } }
121121
}
122122
}
123+
namespace System.ClientModel
124+
{
125+
public abstract partial class AuthenticationTokenProvider
126+
{
127+
protected AuthenticationTokenProvider() { }
128+
public abstract System.ClientModel.Primitives.GetTokenOptions? CreateTokenOptions(System.Collections.Generic.IReadOnlyDictionary<string, object> properties);
129+
public abstract System.ClientModel.Primitives.AccessToken GetToken(System.ClientModel.Primitives.GetTokenOptions properties, System.Threading.CancellationToken cancellationToken);
130+
public abstract System.Threading.Tasks.ValueTask<System.ClientModel.Primitives.AccessToken> GetTokenAsync(System.ClientModel.Primitives.GetTokenOptions properties, System.Threading.CancellationToken cancellationToken);
131+
}
132+
}
133+
namespace System.ClientModel.Primitives
134+
{
135+
public partial class AccessToken
136+
{
137+
public AccessToken(string tokenValue, string tokenType, System.DateTimeOffset expiresOn, System.DateTimeOffset? refreshOn = default(System.DateTimeOffset?)) { }
138+
public System.DateTimeOffset ExpiresOn { get { throw null; } }
139+
public System.DateTimeOffset? RefreshOn { get { throw null; } }
140+
public string TokenType { get { throw null; } }
141+
public string TokenValue { get { throw null; } }
142+
}
143+
public partial class GetTokenOptions
144+
{
145+
public const string AuthorizationUrlPropertyName = "authorizationUrl";
146+
public const string RefreshUrlPropertyName = "refreshUrl";
147+
public const string ScopesPropertyName = "scopes";
148+
public const string TokenUrlPropertyName = "tokenUrl";
149+
public GetTokenOptions(System.ReadOnlyMemory<string> scopes, System.Collections.Generic.IReadOnlyDictionary<string, object> properties) { }
150+
public System.Collections.Generic.IReadOnlyDictionary<string, object> Properties { get { throw null; } }
151+
public System.ReadOnlyMemory<string> Scopes { get { throw null; } }
152+
public System.ClientModel.Primitives.GetTokenOptions WithAdditionalScopes(System.ReadOnlyMemory<string> additionalScopes) { throw null; }
153+
}
154+
public partial class OAuth2BearerTokenAuthenticationPolicy : System.ClientModel.Primitives.PipelinePolicy
155+
{
156+
public OAuth2BearerTokenAuthenticationPolicy(System.ClientModel.AuthenticationTokenProvider tokenProvider, System.Collections.Generic.IEnumerable<System.Collections.Generic.IReadOnlyDictionary<string, object>> contexts) { }
157+
public override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { }
158+
public override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { throw null; }
159+
}
160+
}

sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.net6.0.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,41 @@ public ProvisionableTemplateAttribute(string resourceName) { }
120120
public string ResourceName { get { throw null; } }
121121
}
122122
}
123+
namespace System.ClientModel
124+
{
125+
public abstract partial class AuthenticationTokenProvider
126+
{
127+
protected AuthenticationTokenProvider() { }
128+
public abstract System.ClientModel.Primitives.GetTokenOptions? CreateTokenOptions(System.Collections.Generic.IReadOnlyDictionary<string, object> properties);
129+
public abstract System.ClientModel.Primitives.AccessToken GetToken(System.ClientModel.Primitives.GetTokenOptions properties, System.Threading.CancellationToken cancellationToken);
130+
public abstract System.Threading.Tasks.ValueTask<System.ClientModel.Primitives.AccessToken> GetTokenAsync(System.ClientModel.Primitives.GetTokenOptions properties, System.Threading.CancellationToken cancellationToken);
131+
}
132+
}
133+
namespace System.ClientModel.Primitives
134+
{
135+
public partial class AccessToken
136+
{
137+
public AccessToken(string tokenValue, string tokenType, System.DateTimeOffset expiresOn, System.DateTimeOffset? refreshOn = default(System.DateTimeOffset?)) { }
138+
public System.DateTimeOffset ExpiresOn { get { throw null; } }
139+
public System.DateTimeOffset? RefreshOn { get { throw null; } }
140+
public string TokenType { get { throw null; } }
141+
public string TokenValue { get { throw null; } }
142+
}
143+
public partial class GetTokenOptions
144+
{
145+
public const string AuthorizationUrlPropertyName = "authorizationUrl";
146+
public const string RefreshUrlPropertyName = "refreshUrl";
147+
public const string ScopesPropertyName = "scopes";
148+
public const string TokenUrlPropertyName = "tokenUrl";
149+
public GetTokenOptions(System.ReadOnlyMemory<string> scopes, System.Collections.Generic.IReadOnlyDictionary<string, object> properties) { }
150+
public System.Collections.Generic.IReadOnlyDictionary<string, object> Properties { get { throw null; } }
151+
public System.ReadOnlyMemory<string> Scopes { get { throw null; } }
152+
public System.ClientModel.Primitives.GetTokenOptions WithAdditionalScopes(System.ReadOnlyMemory<string> additionalScopes) { throw null; }
153+
}
154+
public partial class OAuth2BearerTokenAuthenticationPolicy : System.ClientModel.Primitives.PipelinePolicy
155+
{
156+
public OAuth2BearerTokenAuthenticationPolicy(System.ClientModel.AuthenticationTokenProvider tokenProvider, System.Collections.Generic.IEnumerable<System.Collections.Generic.IReadOnlyDictionary<string, object>> contexts) { }
157+
public override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { }
158+
public override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { throw null; }
159+
}
160+
}

sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.net8.0.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,41 @@ public ProvisionableTemplateAttribute(string resourceName) { }
120120
public string ResourceName { get { throw null; } }
121121
}
122122
}
123+
namespace System.ClientModel
124+
{
125+
public abstract partial class AuthenticationTokenProvider
126+
{
127+
protected AuthenticationTokenProvider() { }
128+
public abstract System.ClientModel.Primitives.GetTokenOptions? CreateTokenOptions(System.Collections.Generic.IReadOnlyDictionary<string, object> properties);
129+
public abstract System.ClientModel.Primitives.AccessToken GetToken(System.ClientModel.Primitives.GetTokenOptions properties, System.Threading.CancellationToken cancellationToken);
130+
public abstract System.Threading.Tasks.ValueTask<System.ClientModel.Primitives.AccessToken> GetTokenAsync(System.ClientModel.Primitives.GetTokenOptions properties, System.Threading.CancellationToken cancellationToken);
131+
}
132+
}
133+
namespace System.ClientModel.Primitives
134+
{
135+
public partial class AccessToken
136+
{
137+
public AccessToken(string tokenValue, string tokenType, System.DateTimeOffset expiresOn, System.DateTimeOffset? refreshOn = default(System.DateTimeOffset?)) { }
138+
public System.DateTimeOffset ExpiresOn { get { throw null; } }
139+
public System.DateTimeOffset? RefreshOn { get { throw null; } }
140+
public string TokenType { get { throw null; } }
141+
public string TokenValue { get { throw null; } }
142+
}
143+
public partial class GetTokenOptions
144+
{
145+
public const string AuthorizationUrlPropertyName = "authorizationUrl";
146+
public const string RefreshUrlPropertyName = "refreshUrl";
147+
public const string ScopesPropertyName = "scopes";
148+
public const string TokenUrlPropertyName = "tokenUrl";
149+
public GetTokenOptions(System.ReadOnlyMemory<string> scopes, System.Collections.Generic.IReadOnlyDictionary<string, object> properties) { }
150+
public System.Collections.Generic.IReadOnlyDictionary<string, object> Properties { get { throw null; } }
151+
public System.ReadOnlyMemory<string> Scopes { get { throw null; } }
152+
public System.ClientModel.Primitives.GetTokenOptions WithAdditionalScopes(System.ReadOnlyMemory<string> additionalScopes) { throw null; }
153+
}
154+
public partial class OAuth2BearerTokenAuthenticationPolicy : System.ClientModel.Primitives.PipelinePolicy
155+
{
156+
public OAuth2BearerTokenAuthenticationPolicy(System.ClientModel.AuthenticationTokenProvider tokenProvider, System.Collections.Generic.IEnumerable<System.Collections.Generic.IReadOnlyDictionary<string, object>> contexts) { }
157+
public override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { }
158+
public override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { throw null; }
159+
}
160+
}

sdk/core/Azure.Core.Experimental/api/Azure.Core.Experimental.netstandard2.0.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,41 @@ public ProvisionableTemplateAttribute(string resourceName) { }
120120
public string ResourceName { get { throw null; } }
121121
}
122122
}
123+
namespace System.ClientModel
124+
{
125+
public abstract partial class AuthenticationTokenProvider
126+
{
127+
protected AuthenticationTokenProvider() { }
128+
public abstract System.ClientModel.Primitives.GetTokenOptions? CreateTokenOptions(System.Collections.Generic.IReadOnlyDictionary<string, object> properties);
129+
public abstract System.ClientModel.Primitives.AccessToken GetToken(System.ClientModel.Primitives.GetTokenOptions properties, System.Threading.CancellationToken cancellationToken);
130+
public abstract System.Threading.Tasks.ValueTask<System.ClientModel.Primitives.AccessToken> GetTokenAsync(System.ClientModel.Primitives.GetTokenOptions properties, System.Threading.CancellationToken cancellationToken);
131+
}
132+
}
133+
namespace System.ClientModel.Primitives
134+
{
135+
public partial class AccessToken
136+
{
137+
public AccessToken(string tokenValue, string tokenType, System.DateTimeOffset expiresOn, System.DateTimeOffset? refreshOn = default(System.DateTimeOffset?)) { }
138+
public System.DateTimeOffset ExpiresOn { get { throw null; } }
139+
public System.DateTimeOffset? RefreshOn { get { throw null; } }
140+
public string TokenType { get { throw null; } }
141+
public string TokenValue { get { throw null; } }
142+
}
143+
public partial class GetTokenOptions
144+
{
145+
public const string AuthorizationUrlPropertyName = "authorizationUrl";
146+
public const string RefreshUrlPropertyName = "refreshUrl";
147+
public const string ScopesPropertyName = "scopes";
148+
public const string TokenUrlPropertyName = "tokenUrl";
149+
public GetTokenOptions(System.ReadOnlyMemory<string> scopes, System.Collections.Generic.IReadOnlyDictionary<string, object> properties) { }
150+
public System.Collections.Generic.IReadOnlyDictionary<string, object> Properties { get { throw null; } }
151+
public System.ReadOnlyMemory<string> Scopes { get { throw null; } }
152+
public System.ClientModel.Primitives.GetTokenOptions WithAdditionalScopes(System.ReadOnlyMemory<string> additionalScopes) { throw null; }
153+
}
154+
public partial class OAuth2BearerTokenAuthenticationPolicy : System.ClientModel.Primitives.PipelinePolicy
155+
{
156+
public OAuth2BearerTokenAuthenticationPolicy(System.ClientModel.AuthenticationTokenProvider tokenProvider, System.Collections.Generic.IEnumerable<System.Collections.Generic.IReadOnlyDictionary<string, object>> contexts) { }
157+
public override void Process(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { }
158+
public override System.Threading.Tasks.ValueTask ProcessAsync(System.ClientModel.Primitives.PipelineMessage message, System.Collections.Generic.IReadOnlyList<System.ClientModel.Primitives.PipelinePolicy> pipeline, int currentIndex) { throw null; }
159+
}
160+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Azure.Core;
7+
8+
namespace System.ClientModel.Primitives;
9+
10+
/// <summary>
11+
/// Represents an OAuth token and its metadata.
12+
/// </summary>
13+
public class AccessToken
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="AccessToken"/> class.
17+
/// </summary>
18+
/// <param name="tokenValue">The access token value.</param>
19+
/// <param name="tokenType">The type of the access token (e.g., "Bearer").</param>
20+
/// <param name="expiresOn">The date and time when the token expires.</param>
21+
/// <param name="refreshOn">Optional. The date and time when the token should be refreshed. Default is null.</param>
22+
/// <exception cref="ArgumentException">Thrown when <paramref name="tokenValue"/> is null or empty.</exception>
23+
public AccessToken(string tokenValue, string tokenType, DateTimeOffset expiresOn, DateTimeOffset? refreshOn = null)
24+
{
25+
Argument.AssertNotNullOrEmpty(tokenValue, nameof(tokenValue));
26+
27+
TokenValue = tokenValue;
28+
TokenType = tokenType;
29+
ExpiresOn = expiresOn;
30+
RefreshOn = refreshOn;
31+
}
32+
33+
/// <summary>
34+
/// Get the token value.
35+
/// </summary>
36+
public string TokenValue { get; }
37+
38+
/// <summary>
39+
/// Gets the type of the token.
40+
/// </summary>
41+
public string TokenType { get; }
42+
43+
/// <summary>
44+
/// Gets the time when the provided token expires.
45+
/// </summary>
46+
public DateTimeOffset ExpiresOn { get; }
47+
48+
/// <summary>
49+
/// Gets the time when the token should be refreshed.
50+
/// </summary>
51+
public DateTimeOffset? RefreshOn { get; }
52+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System.ClientModel.Primitives;
5+
using System.Collections.Generic;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
9+
namespace System.ClientModel;
10+
11+
/// <summary>
12+
/// The base class for all <see cref="AuthenticationTokenProvider"/> implementations.
13+
/// </summary>
14+
public abstract class AuthenticationTokenProvider
15+
{
16+
/// <summary>
17+
/// Creates a new instance of <see cref="GetTokenOptions"/> using the provided <paramref name="properties"/>.
18+
/// </summary>
19+
/// <param name="properties"></param>
20+
/// <returns></returns>
21+
public abstract GetTokenOptions? CreateTokenOptions(IReadOnlyDictionary<string, object> properties);
22+
23+
/// <summary>
24+
/// Gets a token from the auth provider.
25+
/// </summary>
26+
/// <param name="properties">The options used by the <see cref="AuthenticationTokenProvider"/> to make a token request.</param>
27+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
28+
/// <returns></returns>
29+
public abstract AccessToken GetToken(GetTokenOptions properties, CancellationToken cancellationToken);
30+
31+
/// <summary>
32+
/// Gets the token.
33+
/// </summary>
34+
/// <param name="properties">The options used by the <see cref="AuthenticationTokenProvider"/> to make a token request.</param>
35+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
36+
/// <returns></returns>
37+
public abstract ValueTask<AccessToken> GetTokenAsync(GetTokenOptions properties, CancellationToken cancellationToken);
38+
}

0 commit comments

Comments
 (0)