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

OAuth2Manager Implementation #4828

Merged
merged 10 commits into from
Oct 30, 2024
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
25 changes: 25 additions & 0 deletions WindowsAppRuntime.sln
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PackageManager.Test.M.White
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PackageManager.Test.M.White.msix", "test\PackageManager\data\PackageManager.Test.M.White.msix\PackageManager.Test.M.White.msix.vcxproj", "{28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OAuth", "OAuth", "{1A6F936D-7350-4177-8195-146BDDFACF3B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OAuth", "dev\OAuth\OAuth.vcxitems", "{3E7FD510-8B66-40E7-A80B-780CB8972F83}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Security.Authentication.OAuth.Projection", "dev\Projections\CS\Microsoft.Security.Authentication.OAuth\Microsoft.Security.Authentication.OAuth.Projection.csproj", "{1D24CC70-85B1-4864-B847-3328F40AF01E}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Interop", "Interop", "{3B706C5C-55E0-4B76-BF59-89E20FE46795}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CameraCaptureUI", "CameraCaptureUI", "{0833D8EF-6E11-4133-B0EE-9B7625CD615E}"
Expand Down Expand Up @@ -1883,6 +1888,22 @@ Global
{28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|x64.Build.0 = Release|x64
{28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|x86.ActiveCfg = Release|Win32
{28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF}.Release|x86.Build.0 = Release|Win32
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Debug|Any CPU.ActiveCfg = Debug|x64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Debug|Any CPU.Build.0 = Debug|x64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Debug|ARM64.ActiveCfg = Debug|arm64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Debug|ARM64.Build.0 = Debug|arm64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Debug|x64.ActiveCfg = Debug|x64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Debug|x64.Build.0 = Debug|x64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Debug|x86.ActiveCfg = Debug|x86
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Debug|x86.Build.0 = Debug|x86
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Release|Any CPU.ActiveCfg = Release|x64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Release|Any CPU.Build.0 = Release|x64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Release|ARM64.ActiveCfg = Release|arm64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Release|ARM64.Build.0 = Release|arm64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Release|x64.ActiveCfg = Release|x64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Release|x64.Build.0 = Release|x64
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Release|x86.ActiveCfg = Release|x86
{1D24CC70-85B1-4864-B847-3328F40AF01E}.Release|x86.Build.0 = Release|x86
{1DAA2342-CF55-48E5-B49C-982FA5C07014}.Debug|Any CPU.ActiveCfg = Debug|x64
{1DAA2342-CF55-48E5-B49C-982FA5C07014}.Debug|Any CPU.Build.0 = Debug|x64
{1DAA2342-CF55-48E5-B49C-982FA5C07014}.Debug|ARM64.ActiveCfg = Debug|x64
Expand Down Expand Up @@ -2093,6 +2114,9 @@ Global
{7C240089-0F22-4247-9C91-51255C8DC18B} = {6213B1A3-E854-498F-AAFA-4CFC1E71023E}
{AC79B8FF-4C27-4326-AD20-BBC70059FF51} = {7C240089-0F22-4247-9C91-51255C8DC18B}
{28DCF9CE-D9F4-4A7D-8AD1-F2EFC0D3B4DF} = {6759ECC6-9381-4172-89E6-853F81A03D28}
{1A6F936D-7350-4177-8195-146BDDFACF3B} = {448ED2E5-0B37-4D97-9E6B-8C10A507976A}
{3E7FD510-8B66-40E7-A80B-780CB8972F83} = {1A6F936D-7350-4177-8195-146BDDFACF3B}
{1D24CC70-85B1-4864-B847-3328F40AF01E} = {716C26A0-E6B0-4981-8412-D14A4D410531}
{3B706C5C-55E0-4B76-BF59-89E20FE46795} = {448ED2E5-0B37-4D97-9E6B-8C10A507976A}
{0833D8EF-6E11-4133-B0EE-9B7625CD615E} = {3B706C5C-55E0-4B76-BF59-89E20FE46795}
{95409D1E-843F-4316-8D8E-471B3E203F94} = {0833D8EF-6E11-4133-B0EE-9B7625CD615E}
Expand All @@ -2106,6 +2130,7 @@ Global
test\inc\inc.vcxitems*{08bc78e0-63c6-49a7-81b3-6afc3deac4de}*SharedItemsImports = 4
dev\PushNotifications\PushNotifications.vcxitems*{103c0c23-7ba8-4d44-a63c-83488e2e3a81}*SharedItemsImports = 9
dev\EnvironmentManager\API\Microsoft.Process.Environment.vcxitems*{2f3fad1b-d3df-4866-a3a3-c2c777d55638}*SharedItemsImports = 9
dev\OAuth\OAuth.vcxitems*{3e7fd510-8b66-40e7-a80b-780cb8972f83}*SharedItemsImports = 9
test\inc\inc.vcxitems*{412d023e-8635-4ad2-a0ea-e19e08d36915}*SharedItemsImports = 4
test\inc\inc.vcxitems*{4b30c685-8490-440f-9879-a75d45daa361}*SharedItemsImports = 4
dev\UndockedRegFreeWinRT\UndockedRegFreeWinRT.vcxitems*{56371ca6-144b-4989-a4e9-391ad4fa7651}*SharedItemsImports = 9
Expand Down
4 changes: 4 additions & 0 deletions build/CopyFilesToStagingDir.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windo
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Media.Capture.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.PushNotifications.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Security.AccessControl.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Security.Authentication.OAuth.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Storage.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.System.Power.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.System.winmd $FullPublishDir\Microsoft.WindowsAppRuntime\
Expand Down Expand Up @@ -121,6 +122,8 @@ PublishFile $FullBuildOutput\Microsoft.Windows.PushNotifications.Projection\Micr
PublishFile $FullBuildOutput\Microsoft.Windows.PushNotifications.Projection\Microsoft.Windows.PushNotifications.Projection.pdb $NugetDir\lib\net6.0-windows10.0.17763.0
PublishFile $FullBuildOutput\Microsoft.Windows.Security.AccessControl.Projection\Microsoft.Windows.Security.AccessControl.Projection.dll $NugetDir\lib\net6.0-windows10.0.17763.0
PublishFile $FullBuildOutput\Microsoft.Windows.Security.AccessControl.Projection\Microsoft.Windows.Security.AccessControl.Projection.pdb $NugetDir\lib\net6.0-windows10.0.17763.0
PublishFile $FullBuildOutput\Microsoft.Security.Authentication.OAuth.Projection\Microsoft.Security.Authentication.OAuth.Projection.dll $NugetDir\lib\net6.0-windows10.0.17763.0
PublishFile $FullBuildOutput\Microsoft.Security.Authentication.OAuth.Projection\Microsoft.Security.Authentication.OAuth.Projection.pdb $NugetDir\lib\net6.0-windows10.0.17763.0
PublishFile $FullBuildOutput\Microsoft.Windows.Storage.Projection\Microsoft.Windows.Storage.Projection.dll $NugetDir\lib\net6.0-windows10.0.17763.0
PublishFile $FullBuildOutput\Microsoft.Windows.Storage.Projection\Microsoft.Windows.Storage.Projection.pdb $NugetDir\lib\net6.0-windows10.0.17763.0
PublishFile $FullBuildOutput\Microsoft.Windows.System.Power.Projection\Microsoft.Windows.System.Power.Projection.dll $NugetDir\lib\net6.0-windows10.0.17763.0
Expand Down Expand Up @@ -190,6 +193,7 @@ PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windo
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Media.Capture.winmd $NugetDir\lib\uap10.0
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.PushNotifications.winmd $NugetDir\lib\uap10.0
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Security.AccessControl.winmd $NugetDir\lib\uap10.0
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Security.Authentication.OAuth.winmd $NugetDir\lib\uap10.0
akanpatel2206 marked this conversation as resolved.
Show resolved Hide resolved
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.Storage.winmd $NugetDir\lib\uap10.0
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.System.Power.winmd $NugetDir\lib\uap10.0
PublishFile $FullBuildOutput\WindowsAppRuntime_DLL\StrippedWinMD\Microsoft.Windows.System.winmd $NugetDir\lib\uap10.0
Expand Down
6 changes: 6 additions & 0 deletions build/NuSpecs/AppxManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
<Path>Microsoft.WindowsAppRuntime.dll</Path>
<!-- NOTE: Keep ActivationClass elements sorted by absolute ActivatableClassId (namespace.class) -->

<!-- OAuth -->
<ActivatableClass ActivatableClassId="Microsoft.Security.Authentication.OAuth.OAuth2Manager" ThreadingModel="both" />
<ActivatableClass ActivatableClassId="Microsoft.Security.Authentication.OAuth.AuthRequestParams" ThreadingModel="both" />
<ActivatableClass ActivatableClassId="Microsoft.Security.Authentication.OAuth.ClientAuthentication" ThreadingModel="both" />
<ActivatableClass ActivatableClassId="Microsoft.Security.Authentication.OAuth.TokenRequestParams" ThreadingModel="both" />

<!-- Dynamic Dependency -->
<ActivatableClass ActivatableClassId="Microsoft.Windows.ApplicationModel.DynamicDependency.AddPackageDependencyOptions" ThreadingModel="both" />
<ActivatableClass ActivatableClassId="Microsoft.Windows.ApplicationModel.DynamicDependency.CreatePackageDependencyOptions" ThreadingModel="both" />
Expand Down
6 changes: 6 additions & 0 deletions build/NuSpecs/WindowsAppSDK-Nuget-Native.WinRt.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<Implementation Condition="'$(WindowsAppSDKFrameworkPackage)' != 'true'">$(MSBuildThisFileDirectory)..\..\runtimes\win10-$(_WindowsAppSDKFoundationPlatform)\native\Microsoft.WindowsAppRuntime.dll</Implementation>
<IsWinMDFile>true</IsWinMDFile>
</Reference>
<Reference Include="Microsoft.Security.Authentication.OAuth.winmd"
Condition="Exists('$(MSBuildThisFileDirectory)..\..\lib\uap10.0\Microsoft.Security.Authentication.OAuth.winmd')">
<HintPath>$(MSBuildThisFileDirectory)..\..\lib\uap10.0\Microsoft.Security.Authentication.OAuth.winmd</HintPath>
<Implementation Condition="'$(WindowsAppSDKFrameworkPackage)' != 'true'">$(MSBuildThisFileDirectory)..\..\runtimes\win10-$(_WindowsAppSDKFoundationPlatform)\native\Microsoft.WindowsAppRuntime.dll</Implementation>
<IsWinMDFile>true</IsWinMDFile>
</Reference>
<Reference Include="Microsoft.Windows.Media.Capture.winmd"
Condition="Exists('$(MSBuildThisFileDirectory)..\..\lib\uap10.0\Microsoft.Windows.Media.Capture.winmd')">
<HintPath>$(MSBuildThisFileDirectory)..\..\lib\uap10.0\Microsoft.Windows.Media.Capture.winmd</HintPath>
Expand Down
7 changes: 7 additions & 0 deletions build/NuSpecs/WindowsAppSDK-Nuget-Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
<Implementation>Microsoft.WindowsAppRuntime.dll</Implementation>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="$(MSBuildThisFileDirectory)..\..\lib\uap10.0\Microsoft.Security.Authentication.OAuth.winmd"
Condition="Exists('$(MSBuildThisFileDirectory)..\..\lib\uap10.0\Microsoft.Security.Authentication.OAuth.winmd')">
<Private>false</Private>
<Implementation>Microsoft.WindowsAppRuntime.dll</Implementation>
</Reference>
</ItemGroup>

<ItemGroup>
<Reference Include="$(MSBuildThisFileDirectory)..\..\lib\uap10.0\Microsoft.Windows.Media.Capture.winmd"
Expand Down
1 change: 0 additions & 1 deletion dev/Common/TelemetryHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ class TelemetryHelper
return CensorFilePath(processName.get());
}
};

32 changes: 32 additions & 0 deletions dev/Common/TerminalVelocityFeatures-OAuth.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

// THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT IT

// INPUT FILE: dev\common\TerminalVelocityFeatures-OAuth.xml
// OPTIONS: -Channel Experimental -Language C++ -Namespace Microsoft.Security.Authentication.OAuth -Path dev\common\TerminalVelocityFeatures-OAuth.xml -Output dev\common\TerminalVelocityFeatures-OAuth.h

#if defined(__midlrt)
namespace features
{
feature_name Feature_OAuth = { DisabledByDefault, FALSE };
}
#endif // defined(__midlrt)

// Feature constants
#define WINDOWSAPPRUNTIME_MICROSOFT_SECURITY_AUTHENTICATION_OAUTH_FEATURE_OAUTH_ENABLED 1

#if defined(__cplusplus)

namespace Microsoft::Security::Authentication::OAuth
{

__pragma(detect_mismatch("ODR_violation_WINDOWSAPPRUNTIME_MICROSOFT_WINDOWS_SECURITY_AUTHENTICATION_OAUTH_FEATURE_OAUTH_ENABLED_mismatch", "AlwaysEnabled"))
struct Feature_OAuth
{
static constexpr bool IsEnabled() { return WINDOWSAPPRUNTIME_MICROSOFT_SECURITY_AUTHENTICATION_OAUTH_FEATURE_OAUTH_ENABLED == 1; }
};

} // namespace Microsoft.Security.Authentication.OAuth

#endif // defined(__cplusplus)
16 changes: 16 additions & 0 deletions dev/Common/TerminalVelocityFeatures-OAuth.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<features xmlns="http://microsoft.com/windowsappsdk/TerminalVelocity/20210729/TerminalVelocityFeatures.xsd">

<!-- Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See LICENSE in the project root for license information.
-->

<!-- See docs/Coding-Guidelines/TerminalVelocity.md for more info. -->

<!-- Enabled variants -->
<feature>
<name>Feature_OAuth</name>
<description>OAuth for the WindowsAppRuntime</description>
<state>AlwaysEnabled</state>
</feature>
</features>
83 changes: 83 additions & 0 deletions dev/OAuth/AuthFailure.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#include <pch.h>
#include "common.h"

#include "AuthFailure.h"

#include <Microsoft.Security.Authentication.OAuth.AuthFailure.g.cpp>

using namespace std::literals;
using namespace winrt::Microsoft::Security::Authentication::OAuth;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Foundation::Collections;

namespace winrt::Microsoft::Security::Authentication::OAuth::implementation
{
AuthFailure::AuthFailure(const Uri& responseUri)
{
std::map<winrt::hstring, winrt::hstring> additionalParams;

auto parseComponents = [&](const winrt::hstring& str) {
if (str.empty())
{
return; // Avoid unnecessary construction/activation
}

for (auto&& entry : WwwFormUrlDecoder(str))
{
auto name = entry.Name();
if (name == L"error"sv)
{
m_error = entry.Value();
}
else if (name == L"error_description"sv)
{
m_errorDescription = entry.Value();
}
else if (name == L"error_uri"sv)
{
m_errorUri = Uri(entry.Value());
}
else if (name == L"state"sv)
{
m_state = entry.Value();
}
else
{
additionalParams.emplace(std::move(name), entry.Value());
}
}
};

parseComponents(responseUri.Query());
parseComponents(fragment_component(responseUri));
akanpatel2206 marked this conversation as resolved.
Show resolved Hide resolved

m_additionalParams = winrt::single_threaded_map(std::move(additionalParams)).GetView();
}

winrt::hstring AuthFailure::Error()
{
return m_error;
}

winrt::hstring AuthFailure::ErrorDescription()
{
return m_errorDescription;
}

Uri AuthFailure::ErrorUri()
{
return m_errorUri;
}

winrt::hstring AuthFailure::State()
{
return m_state;
}

IMapView<winrt::hstring, winrt::hstring> AuthFailure::AdditionalParams()
{
return m_additionalParams;
}
}
25 changes: 25 additions & 0 deletions dev/OAuth/AuthFailure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#pragma once
#include <Microsoft.Security.Authentication.OAuth.AuthFailure.g.h>

namespace winrt::Microsoft::Security::Authentication::OAuth::implementation
{
struct AuthFailure : AuthFailureT<AuthFailure>
{
AuthFailure(const foundation::Uri& responseUri);
jonwis marked this conversation as resolved.
Show resolved Hide resolved

winrt::hstring Error();
winrt::hstring ErrorDescription();
foundation::Uri ErrorUri();
winrt::hstring State();
collections::IMapView<winrt::hstring, winrt::hstring> AdditionalParams();

private:
winrt::hstring m_error;
winrt::hstring m_errorDescription;
foundation::Uri m_errorUri{ nullptr };
winrt::hstring m_state;
collections::IMapView<winrt::hstring, winrt::hstring> m_additionalParams;
};
}
Loading