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

authentication/oauth2 #4646

Draft
wants to merge 2 commits into
base: feature/v3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/testProjects.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"CadlRanchProjectsNonAzure":[
"type/array",
"type/dictionary",
"authentication/oauth2",
"authentication/http/custom"
],
"TestServerProjects": [
Expand Down
4 changes: 4 additions & 0 deletions src/AutoRest.CSharp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\authentication\\http\\custom\\src\\Generated -n"
},
"typespec-nonAzure-authentication/oauth2": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\authentication\\oauth2\\src\\Generated -n"
},
"typespec-nonAzure-type/array": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\type\\array\\src\\Generated -n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Authentication.OAuth2", "src\Authentication.OAuth2.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Authentication.OAuth2.Tests", "tests\Authentication.OAuth2.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>This is the Authentication.OAuth2 client library for developing .NET applications with rich experience.</Description>
<AssemblyTitle>SDK Code Generation Authentication.OAuth2</AssemblyTitle>
<Version>1.0.0-beta.1</Version>
<PackageTags>Authentication.OAuth2</PackageTags>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.ClientModel" Version="1.1.0-beta.3" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
</ItemGroup>
</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// <auto-generated/>

#nullable disable

using System;
using System.Collections;
using System.Collections.Generic;

namespace Authentication.OAuth2
{
internal static class Argument
{
public static void AssertNotNull<T>(T value, string name)
{
if (value is null)
{
throw new ArgumentNullException(name);
}
}

public static void AssertNotNull<T>(T? value, string name)
where T : struct
{
if (!value.HasValue)
{
throw new ArgumentNullException(name);
}
}

public static void AssertNotNullOrEmpty<T>(IEnumerable<T> value, string name)
{
if (value is null)
{
throw new ArgumentNullException(name);
}
if (value is ICollection<T> collectionOfT && collectionOfT.Count == 0)
{
throw new ArgumentException("Value cannot be an empty collection.", name);
}
if (value is ICollection collection && collection.Count == 0)
{
throw new ArgumentException("Value cannot be an empty collection.", name);
}
using IEnumerator<T> e = value.GetEnumerator();
if (!e.MoveNext())
{
throw new ArgumentException("Value cannot be an empty collection.", name);
}
}

public static void AssertNotNullOrEmpty(string value, string name)
{
if (value is null)
{
throw new ArgumentNullException(name);
}
if (value.Length == 0)
{
throw new ArgumentException("Value cannot be an empty string.", name);
}
}

public static void AssertNotNullOrWhiteSpace(string value, string name)
{
if (value is null)
{
throw new ArgumentNullException(name);
}
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name);
}
}

public static void AssertNotDefault<T>(ref T value, string name)
where T : struct, IEquatable<T>
{
if (value.Equals(default))
{
throw new ArgumentException("Value cannot be empty.", name);
}
}

public static void AssertInRange<T>(T value, T minimum, T maximum, string name)
where T : notnull, IComparable<T>
{
if (minimum.CompareTo(value) > 0)
{
throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed.");
}
if (maximum.CompareTo(value) < 0)
{
throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed.");
}
}

public static void AssertEnumDefined(Type enumType, object value, string name)
{
if (!Enum.IsDefined(enumType, value))
{
throw new ArgumentException($"Value not defined for {enumType.FullName}.", name);
}
}

public static T CheckNotNull<T>(T value, string name)
where T : class
{
AssertNotNull(value, name);
return value;
}

public static string CheckNotNullOrEmpty(string value, string name)
{
AssertNotNullOrEmpty(value, name);
return value;
}

public static void AssertNull<T>(T value, string name, string message = null)
{
if (value != null)
{
throw new ArgumentException(message ?? "Value must be null.", name);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// <auto-generated/>

#nullable disable

using System.ClientModel;
using System.ClientModel.Primitives;
using System.Threading.Tasks;

namespace Authentication.OAuth2
{
internal static class ClientPipelineExtensions
{
public static async ValueTask<PipelineResponse> ProcessMessageAsync(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options)
{
await pipeline.SendAsync(message).ConfigureAwait(false);

if (message.Response.IsError && (options?.ErrorOptions & ClientErrorBehaviors.NoThrow) != ClientErrorBehaviors.NoThrow)
{
throw await ClientResultException.CreateAsync(message.Response).ConfigureAwait(false);
}

return message.Response;
}

public static PipelineResponse ProcessMessage(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options)
{
pipeline.Send(message);

if (message.Response.IsError && (options?.ErrorOptions & ClientErrorBehaviors.NoThrow) != ClientErrorBehaviors.NoThrow)
{
throw new ClientResultException(message.Response);
}

return message.Response;
}

public static async ValueTask<ClientResult<bool>> ProcessHeadAsBoolMessageAsync(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options)
{
PipelineResponse response = await pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false);
switch (response.Status)
{
case >= 200 and < 300:
return ClientResult.FromValue(true, response);
case >= 400 and < 500:
return ClientResult.FromValue(false, response);
default:
return new ErrorResult<bool>(response, new ClientResultException(response));
}
}

public static ClientResult<bool> ProcessHeadAsBoolMessage(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options)
{
PipelineResponse response = pipeline.ProcessMessage(message, options);
switch (response.Status)
{
case >= 200 and < 300:
return ClientResult.FromValue(true, response);
case >= 400 and < 500:
return ClientResult.FromValue(false, response);
default:
return new ErrorResult<bool>(response, new ClientResultException(response));
}
}
}
}