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

Conversation

akanpatel2206
Copy link
Contributor

API spec: #4772
Issue: #441

This new WinAppSDK version of the AuthManager is different than the existing public
WebAuthenticationBroker
API. We've opted to follow OAuth best practices more closely - e.g. using user's default browser as part of version 1. The best practices for the API are taken from the
IETF(Internet Engineering Task Force) OAuth 2.0 Authorization Framework RFC 6749,
Proof Key for Code Exchange (PKCE) RFC 7636,
and OAuth 2.0 for Native Apps RFC 8252.

It is recommended to read through the mentioned RFCs for better understanding of the design used in the API spec and the implementation code.
Please go through the API spec to understand the implementation.

Testing
Successful local build
Produced an experimental NuGet package leveraging the aggregator build pipeline, and tested it using a sample app.

Note: The Interactive Experiences package has been incorporated as a dependency in the Foundation repo to utilize Microsoft.UI API features.

Pending Action Items:
Ensure that Maestro recognizes the dependency updates being made to the Foundation branch (the Interactive Experiences package has been integrated into the Foundation repo)
Unit tests
Publishing Public/Private symbols
Create sample apps for WinAppSDK-samples repo.
Test support for C# projections

A microsoft employee must use /azp run to validate using the pipelines below.

WARNING:
Comments made by azure-pipelines bot maybe inaccurate.
Please see pipeline link to verify that the build is being ran.

For status checks on the main branch, please use TransportPackage-Foundation-PR
(https://microsoft.visualstudio.com/ProjectReunion/_build?definitionId=81063&_a=summary)
and run the build against your PR branch with the default parameters.

@akanpatel2206
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@akanpatel
Copy link

build/CopyFilesToStagingDir.ps1 Show resolved Hide resolved
dev/OAuth/AuthFailure.h Show resolved Hide resolved
dev/OAuth/AuthRequestAsyncOperation.h Outdated Show resolved Hide resolved
dev/OAuth/AuthRequestAsyncOperation.h Outdated Show resolved Hide resolved
return; // Avoid unnecessary construction/activation
}

for (auto&& entry : WwwFormUrlDecoder(str))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: See structured binding on cppreference, so you can say for (auto& [name, value] : WwwFormUrlDecoder(str))

dev/OAuth/OAuth2Manager.cpp Outdated Show resolved Hide resolved
dev/OAuth/OAuth2Manager.cpp Outdated Show resolved Hide resolved
dev/OAuth/OAuth2Manager.cpp Outdated Show resolved Hide resolved
}
catch (...)
{
co_return implementation::TokenRequestResult::MakeFailure(std::move(response),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these "catch and return" points, consider using LOG_CAUGHT_EXCEPTION() so you can see what's happening.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official Winappsdk docs mention how we can pull out the relevant hr code and message.
https://github.com/microsoft/WindowsAppSDK/blob/743f4551dcd8eda8db1136d7f61a8ecc7f338325/docs/Coding-Guidelines/Languages-CPP.md

Would it also be helpful if we can fire a telemetry with the error codes for debugging and tracking metrics?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used LOG_CAUGHT_EXCEPTION();

dev/OAuth/OAuth2Manager.cpp Outdated Show resolved Hide resolved
@Saharsh979 Saharsh979 added this to the 1.7 milestone Oct 25, 2024
@akanpatel
Copy link

/azp run

Copy link

Commenter does not have sufficient privileges for PR 4828 in repo microsoft/WindowsAppSDK

@akanpatel2206
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@akanpatel2206
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@jonwis jonwis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

dev/OAuth/AuthRequestParams.cpp Show resolved Hide resolved
WINRT_ASSERT(m_finalized);

// Per RFC 6749 section 3.1, the auth endpoint URI *MAY* contain a query string, which must be retained
std::wstring result{ authEndpoint.RawUri() };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised there isn't a "URI builder" that would do this for you! Looks fine as-is.

@akanpatel2206
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -43,6 +43,9 @@
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)winrt_WindowsAppRuntime.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)TelemetryHelper.h">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -27,6 +27,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)Microsoft.Utf8.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)NotificationTelemetryHelper.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)Security.IntegrityLevel.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)TelemetryHelper.h" />

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@akanpatel2206
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@akanpatel2206 akanpatel2206 merged commit 506416b into main Oct 30, 2024
26 checks passed
@akanpatel2206 akanpatel2206 deleted the user/akanpatel2206/OAuth2_impl branch October 30, 2024 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants