From 662b815ee2c5fbab41f2c7bc6d88605d82b334d8 Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Sat, 14 Oct 2023 13:27:08 +0300 Subject: [PATCH 1/3] iOS browser impl for google login --- Assets/Plugins/iOS.meta | 8 ++ Assets/Plugins/iOS/iOSBrowser.m | 30 +++++++ Assets/Plugins/iOS/iOSBrowser.m.meta | 82 +++++++++++++++++++ .../Scripts/WalletsUI/EmbeddedWalletUI.cs | 8 +- 4 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 Assets/Plugins/iOS.meta create mode 100644 Assets/Plugins/iOS/iOSBrowser.m create mode 100644 Assets/Plugins/iOS/iOSBrowser.m.meta diff --git a/Assets/Plugins/iOS.meta b/Assets/Plugins/iOS.meta new file mode 100644 index 00000000..4ccac03a --- /dev/null +++ b/Assets/Plugins/iOS.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 822f9dda6348e3b46a3099bf0727052f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/iOS/iOSBrowser.m b/Assets/Plugins/iOS/iOSBrowser.m new file mode 100644 index 00000000..05dc210b --- /dev/null +++ b/Assets/Plugins/iOS/iOSBrowser.m @@ -0,0 +1,30 @@ +#import +#import +#import + +@interface iOSBrowser : NSObject +@end + +@implementation iOSBrowser + +static UIViewController* GetCurrentViewController() { + UIWindow *window = [[UIApplication sharedApplication] keyWindow]; + UIViewController *rootViewController = window.rootViewController; + + UIViewController *currentController = rootViewController; + while (currentController.presentedViewController) { + currentController = currentController.presentedViewController; + } + return currentController; +} + +void _OpenURL(const char* url) { + NSString *urlString = [NSString stringWithUTF8String:url]; + NSURL *nsURL = [NSURL URLWithString:urlString]; + + SFSafariViewController *safariViewController = [[SFSafariViewController alloc] initWithURL:nsURL]; + UIViewController *currentViewController = GetCurrentViewController(); + [currentViewController presentViewController:safariViewController animated:YES completion:nil]; +} + +@end diff --git a/Assets/Plugins/iOS/iOSBrowser.m.meta b/Assets/Plugins/iOS/iOSBrowser.m.meta new file mode 100644 index 00000000..c1087741 --- /dev/null +++ b/Assets/Plugins/iOS/iOSBrowser.m.meta @@ -0,0 +1,82 @@ +fileFormatVersion: 2 +guid: a8b902c78bc2bc9498f63152b1d05ba8 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 1 + Exclude Linux64: 1 + Exclude OSXUniversal: 1 + Exclude WebGL: 1 + Exclude Win: 1 + Exclude Win64: 1 + Exclude iOS: 0 + - first: + Android: Android + second: + enabled: 0 + settings: + AndroidSharedLibraryType: Executable + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: AnyOS + - first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + CPU: AnyCPU + CompileFlags: + FrameworkDependencies: SafariServices; + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Thirdweb/Core/Scripts/WalletsUI/EmbeddedWalletUI.cs b/Assets/Thirdweb/Core/Scripts/WalletsUI/EmbeddedWalletUI.cs index 966ce236..b02ff66e 100644 --- a/Assets/Thirdweb/Core/Scripts/WalletsUI/EmbeddedWalletUI.cs +++ b/Assets/Thirdweb/Core/Scripts/WalletsUI/EmbeddedWalletUI.cs @@ -152,14 +152,12 @@ private async Task LoginWithGoogle() } #if UNITY_IOS - // [DllImport("__Internal")] - // private static extern void _OpenURL(string url); + [DllImport("__Internal")] + private static extern void _OpenURL(string url); public void OpenURL(string url) { - // _OpenURL(url); - // // TODO: Implement callback - throw new UnityException("Embedded Wallets are not supported on iOS yet!"); + _OpenURL(url); } #elif UNITY_ANDROID public void OpenURL(string url) From 37c366d0f192ffccc13ae6a932fd8f370800610a Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Mon, 16 Oct 2023 12:58:50 +0300 Subject: [PATCH 2/3] IThirdwebBrowser --- .../Scripts/Browser.meta} | 2 +- .../Core/Scripts/Browser/AndroidBrowser.cs | 65 ++++ .../Scripts/Browser/AndroidBrowser.cs.meta} | 2 +- .../Scripts/Browser/CrossPlatformBrowser.cs | 23 ++ .../Browser/CrossPlatformBrowser.cs.meta | 2 +- .../Core/Scripts/Browser/IOSBrowser.cs | 67 ++++ .../Scripts/Browser/IOSBrowser.cs.meta} | 2 +- .../Core/Scripts/Browser/IThirdwebBrowser.cs | 40 +++ .../Scripts/Browser/IThirdwebBrowser.cs.meta} | 2 +- .../Scripts}/Browser/StandaloneBrowser.cs | 33 +- .../Browser/StandaloneBrowser.cs.meta | 2 +- .../Scripts/WalletsUI/EmbeddedWalletUI.cs | 62 +--- .../Authentication for Unity/CHANGELOG.md | 39 --- .../CHANGELOG.md.meta | 7 - .../Authentication for Unity/Plugins.meta | 8 - .../Authentication for Unity/Plugins/iOS.meta | 8 - .../Plugins/iOS/ASWebAuthenticationSession.mm | 101 ------ .../iOS/ASWebAuthenticationSession.mm.meta | 85 ----- .../Plugins/iOS/Common.h | 40 --- .../Plugins/iOS/Common.h.meta | 27 -- .../Plugins/iOS/WKWebView.mm | 266 --------------- .../Plugins/iOS/WKWebView.mm.meta | 85 ----- .../Authentication for Unity/README.md | 62 ---- .../Authentication for Unity/README.md.meta | 7 - .../Authentication for Unity/Runtime.meta | 8 - .../Runtime/Browser.meta | 3 - .../Browser/ASWebAuthenticationSession.cs | 142 -------- .../ASWebAuthenticationSessionBrowser.cs | 80 ----- .../ASWebAuthenticationSessionError.cs | 14 - .../ASWebAuthenticationSessionErrorCode.cs | 10 - ...SWebAuthenticationSessionErrorCode.cs.meta | 11 - .../Runtime/Browser/BrowserResult.cs | 36 -- .../Runtime/Browser/BrowserResult.cs.meta | 11 - .../Runtime/Browser/BrowserStatus.cs | 9 - .../Runtime/Browser/BrowserStatus.cs.meta | 11 - .../Runtime/Browser/CrossPlatformBrowser.cs | 27 -- .../Runtime/Browser/DeepLinkBrowser.cs | 44 --- .../Runtime/Browser/DeepLinkBrowser.cs.meta | 11 - .../Runtime/Browser/IBrowser.cs | 11 - .../Runtime/Browser/IBrowser.cs.meta | 11 - .../Browser/WKWebViewAuthenticationSession.cs | 101 ------ .../WKWebViewAuthenticationSession.cs.meta | 11 - .../WKWebViewAuthenticationSessionBrowser.cs | 68 ---- ...ebViewAuthenticationSessionBrowser.cs.meta | 11 - .../WKWebViewAuthenticationSessionError.cs | 14 - ...KWebViewAuthenticationSessionError.cs.meta | 11 - ...WKWebViewAuthenticationSessionErrorCode.cs | 9 - ...ViewAuthenticationSessionErrorCode.cs.meta | 11 - .../Runtime/Clients.meta | 3 - .../Runtime/Clients/FacebookAuth.cs | 62 ---- .../Runtime/Clients/FacebookAuth.cs.meta | 3 - .../Runtime/Clients/GitHubAuth.cs | 51 --- .../Runtime/Clients/GitHubAuth.cs.meta | 11 - .../Runtime/Clients/GoogleAuth.cs | 55 --- .../Runtime/Clients/GoogleAuth.cs.meta | 3 - .../Runtime/Clients/MockServerAuth.cs | 20 -- .../Runtime/Clients/MockServerAuth.cs.meta | 3 - .../Runtime/IUserInfo.cs | 25 -- .../Runtime/IUserInfo.cs.meta | 3 - .../Runtime/IUserInfoProvider.cs | 14 - .../Runtime/IUserInfoProvider.cs.meta | 3 - .../Runtime/Mocking.meta | 3 - .../Runtime/Mocking/MockServer.cs | 321 ------------------ .../Runtime/Mocking/MockServer.cs.meta | 3 - .../Mocking/MockServerAccessTokenResponse.cs | 20 -- .../MockServerAccessTokenResponse.cs.meta | 3 - .../Runtime/OAuth2.meta | 3 - .../Runtime/OAuth2/AccessTokenRequest.cs | 49 --- .../Runtime/OAuth2/AccessTokenRequest.cs.meta | 3 - .../Runtime/OAuth2/AccessTokenRequestError.cs | 36 -- .../OAuth2/AccessTokenRequestError.cs.meta | 3 - .../OAuth2/AccessTokenRequestErrorCode.cs | 68 ---- .../AccessTokenRequestErrorCode.cs.meta | 3 - .../OAuth2/AccessTokenRequestException.cs | 43 --- .../AccessTokenRequestException.cs.meta | 3 - .../Runtime/OAuth2/AccessTokenResponse.cs | 96 ------ .../OAuth2/AccessTokenResponse.cs.meta | 3 - .../OAuth2/AccessTokenResponseExtensions.cs | 11 - .../AccessTokenResponseExtensions.cs.meta | 3 - .../Runtime/OAuth2/AuthenticationError.cs | 9 - .../OAuth2/AuthenticationError.cs.meta | 3 - .../Runtime/OAuth2/AuthenticationException.cs | 25 -- .../OAuth2/AuthenticationException.cs.meta | 3 - .../Runtime/OAuth2/AuthenticationSession.cs | 130 ------- .../OAuth2/AuthenticationSession.cs.meta | 3 - .../Runtime/OAuth2/AuthorizationCodeFlow.cs | 317 ----------------- .../OAuth2/AuthorizationCodeFlow.cs.meta | 3 - .../OAuth2/AuthorizationCodeFlowWithPkce.cs | 83 ----- .../AuthorizationCodeFlowWithPkce.cs.meta | 11 - .../OAuth2/AuthorizationCodeRequest.cs | 53 --- .../OAuth2/AuthorizationCodeRequest.cs.meta | 3 - .../OAuth2/AuthorizationCodeRequestError.cs | 39 --- .../AuthorizationCodeRequestError.cs.meta | 3 - .../AuthorizationCodeRequestErrorCode.cs | 70 ---- .../AuthorizationCodeRequestErrorCode.cs.meta | 3 - .../AuthorizationCodeRequestException.cs | 25 -- .../AuthorizationCodeRequestException.cs.meta | 3 - .../OAuth2/AuthorizationCodeResponse.cs | 31 -- .../OAuth2/AuthorizationCodeResponse.cs.meta | 3 - .../Runtime/OAuth2/RefreshTokenRequest.cs | 37 -- .../OAuth2/RefreshTokenRequest.cs.meta | 3 - .../Runtime/Utils.meta | 3 - .../Runtime/Utils/JsonHelper.cs | 61 ---- .../Runtime/Utils/JsonHelper.cs.meta | 3 - .../Runtime/Utils/UrlBuilder.cs | 40 --- .../Runtime/Utils/UrlBuilder.cs.meta | 3 - .../Runtime/Utils/UserInfoParser.cs | 41 --- .../Runtime/Utils/UserInfoParser.cs.meta | 3 - .../Third Party Notices.md | 17 - .../Third Party Notices.md.meta | 7 - 110 files changed, 224 insertions(+), 3456 deletions(-) rename Assets/Thirdweb/{Plugins/Authentication for Unity.meta => Core/Scripts/Browser.meta} (77%) create mode 100644 Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs rename Assets/Thirdweb/{Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSession.cs.meta => Core/Scripts/Browser/AndroidBrowser.cs.meta} (83%) create mode 100644 Assets/Thirdweb/Core/Scripts/Browser/CrossPlatformBrowser.cs rename Assets/Thirdweb/{Plugins/Authentication for Unity/Runtime => Core/Scripts}/Browser/CrossPlatformBrowser.cs.meta (83%) create mode 100644 Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs rename Assets/Thirdweb/{Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionBrowser.cs.meta => Core/Scripts/Browser/IOSBrowser.cs.meta} (83%) create mode 100644 Assets/Thirdweb/Core/Scripts/Browser/IThirdwebBrowser.cs rename Assets/Thirdweb/{Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionError.cs.meta => Core/Scripts/Browser/IThirdwebBrowser.cs.meta} (83%) rename Assets/Thirdweb/{Plugins/Authentication for Unity/Runtime => Core/Scripts}/Browser/StandaloneBrowser.cs (75%) rename Assets/Thirdweb/{Plugins/Authentication for Unity/Runtime => Core/Scripts}/Browser/StandaloneBrowser.cs.meta (83%) delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/CHANGELOG.md delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/CHANGELOG.md.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Plugins.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/ASWebAuthenticationSession.mm delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/ASWebAuthenticationSession.mm.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/Common.h delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/Common.h.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/WKWebView.mm delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/WKWebView.mm.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/README.md delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/README.md.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSession.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionBrowser.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionError.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionErrorCode.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionErrorCode.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserResult.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserResult.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserStatus.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserStatus.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/CrossPlatformBrowser.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/DeepLinkBrowser.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/DeepLinkBrowser.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/IBrowser.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/IBrowser.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSession.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSession.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionBrowser.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionBrowser.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionError.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionError.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionErrorCode.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionErrorCode.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/FacebookAuth.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/FacebookAuth.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GitHubAuth.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GitHubAuth.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GoogleAuth.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GoogleAuth.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/MockServerAuth.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/MockServerAuth.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfo.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfo.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfoProvider.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfoProvider.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServer.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServer.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServerAccessTokenResponse.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServerAccessTokenResponse.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequest.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequest.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestError.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestError.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestErrorCode.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestErrorCode.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestException.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestException.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponse.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponse.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponseExtensions.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponseExtensions.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationError.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationError.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationException.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationException.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationSession.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationSession.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlow.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlow.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlowWithPkce.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlowWithPkce.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequest.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequest.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestError.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestError.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestErrorCode.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestErrorCode.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestException.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestException.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeResponse.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeResponse.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/RefreshTokenRequest.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/RefreshTokenRequest.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/JsonHelper.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/JsonHelper.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UrlBuilder.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UrlBuilder.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UserInfoParser.cs delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UserInfoParser.cs.meta delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Third Party Notices.md delete mode 100644 Assets/Thirdweb/Plugins/Authentication for Unity/Third Party Notices.md.meta diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity.meta b/Assets/Thirdweb/Core/Scripts/Browser.meta similarity index 77% rename from Assets/Thirdweb/Plugins/Authentication for Unity.meta rename to Assets/Thirdweb/Core/Scripts/Browser.meta index 83707943..9b909b71 100644 --- a/Assets/Thirdweb/Plugins/Authentication for Unity.meta +++ b/Assets/Thirdweb/Core/Scripts/Browser.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 4d22191d5a956ef4ab805c7fd26e65ab +guid: 8f8bee9a62b536548b07551d9a3fb3cd folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs b/Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs new file mode 100644 index 00000000..4b28b77a --- /dev/null +++ b/Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs @@ -0,0 +1,65 @@ +#if UNITY_ANDROID + +using System; +using System.Threading; +using System.Threading.Tasks; +using UnityEngine; + +namespace Thirdweb.Browser +{ + public class AndroidBrowser : IThirdwebBrowser + { + private TaskCompletionSource _taskCompletionSource; + + private string _customScheme; + + public async Task Login(string loginUrl, string customScheme, CancellationToken cancellationToken = default) + { + _taskCompletionSource = new TaskCompletionSource(); + + cancellationToken.Register(() => + { + _taskCompletionSource?.TrySetCanceled(); + }); + + _customScheme = customScheme; + + Application.deepLinkActivated += OnDeepLinkActivated; + + try + { + OpenURL(loginUrl); + var completedTask = await Task.WhenAny(_taskCompletionSource.Task, Task.Delay(TimeSpan.FromSeconds(30))); + if (completedTask == _taskCompletionSource.Task) + { + return await _taskCompletionSource.Task; + } + else + { + return new BrowserResult(BrowserStatus.Timeout, null, "The operation timed out."); + } + } + finally + { + Application.deepLinkActivated -= OnDeepLinkActivated; + } + } + + private void OpenURL(string url) + { + AndroidJavaClass thirdwebActivityClass = new("com.unity3d.player.UnityPlayer"); + AndroidJavaObject thirdwebActivity = thirdwebActivityClass.GetStatic("currentActivity"); + thirdwebActivity.Call("OpenCustomTab", url); + } + + private void OnDeepLinkActivated(string url) + { + if (!url.StartsWith(_customScheme)) + return; + + _taskCompletionSource.SetResult(new BrowserResult(BrowserStatus.Success, url)); + } + } +} + +#endif diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSession.cs.meta b/Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs.meta similarity index 83% rename from Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSession.cs.meta rename to Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs.meta index fd6c5372..521319fd 100644 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSession.cs.meta +++ b/Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 541a4af5557ac1841bf28e6ad8277280 +guid: 506fa6dd9c6a15e43abf57767776015c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Thirdweb/Core/Scripts/Browser/CrossPlatformBrowser.cs b/Assets/Thirdweb/Core/Scripts/Browser/CrossPlatformBrowser.cs new file mode 100644 index 00000000..3f07a3a6 --- /dev/null +++ b/Assets/Thirdweb/Core/Scripts/Browser/CrossPlatformBrowser.cs @@ -0,0 +1,23 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Thirdweb.Browser +{ + public class CrossPlatformBrowser : IThirdwebBrowser + { + private IThirdwebBrowser _browser; + + public async Task Login(string loginUrl, string redirectUrl, CancellationToken cancellationToken = default) + { +#if UNITY_ANDROID + _browser = new AndroidBrowser(); +#elif UNITY_IOS + _browser = new IOSBrowser(); +#else + _browser = new StandaloneBrowser(); +#endif + + return await _browser.Login(loginUrl, redirectUrl, cancellationToken); + } + } +} diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/CrossPlatformBrowser.cs.meta b/Assets/Thirdweb/Core/Scripts/Browser/CrossPlatformBrowser.cs.meta similarity index 83% rename from Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/CrossPlatformBrowser.cs.meta rename to Assets/Thirdweb/Core/Scripts/Browser/CrossPlatformBrowser.cs.meta index 070dbffb..7bd19bf0 100644 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/CrossPlatformBrowser.cs.meta +++ b/Assets/Thirdweb/Core/Scripts/Browser/CrossPlatformBrowser.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6222a53e50713374eb3c1b52c19b93bd +guid: d35311e085d5c41498892e95ddeb58c2 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs b/Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs new file mode 100644 index 00000000..11919faf --- /dev/null +++ b/Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs @@ -0,0 +1,67 @@ +#if UNITY_IOS + +using System; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using UnityEngine; + +namespace Thirdweb.Browser +{ + public class IOSBrowser : IThirdwebBrowser + { + private TaskCompletionSource _taskCompletionSource; + + private string _customScheme; + + public async Task Login(string loginUrl, string customScheme, CancellationToken cancellationToken = default) + { + _taskCompletionSource = new TaskCompletionSource(); + + cancellationToken.Register(() => + { + _taskCompletionSource?.TrySetCanceled(); + }); + + _customScheme = customScheme; + + Application.deepLinkActivated += OnDeepLinkActivated; + + try + { + OpenURL(loginUrl); + var completedTask = await Task.WhenAny(_taskCompletionSource.Task, Task.Delay(TimeSpan.FromSeconds(30))); + if (completedTask == _taskCompletionSource.Task) + { + return await _taskCompletionSource.Task; + } + else + { + return new BrowserResult(BrowserStatus.Timeout, null, "The operation timed out."); + } + } + finally + { + Application.deepLinkActivated -= OnDeepLinkActivated; + } + } + + [DllImport("__Internal")] + private static extern void _OpenURL(string url); + + public void OpenURL(string url) + { + _OpenURL(url); + } + + private void OnDeepLinkActivated(string url) + { + if (!url.StartsWith(_customScheme)) + return; + + _taskCompletionSource.SetResult(new BrowserResult(BrowserStatus.Success, url)); + } + } +} + +#endif diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionBrowser.cs.meta b/Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs.meta similarity index 83% rename from Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionBrowser.cs.meta rename to Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs.meta index ae94f652..1712fed1 100644 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionBrowser.cs.meta +++ b/Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6489992ec46101d4dac6424bf755ef6e +guid: 7d1c259a73f330c4b9d0ecf9ceecb47f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Thirdweb/Core/Scripts/Browser/IThirdwebBrowser.cs b/Assets/Thirdweb/Core/Scripts/Browser/IThirdwebBrowser.cs new file mode 100644 index 00000000..6f1aade3 --- /dev/null +++ b/Assets/Thirdweb/Core/Scripts/Browser/IThirdwebBrowser.cs @@ -0,0 +1,40 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Thirdweb.Browser +{ + public interface IThirdwebBrowser + { + Task Login(string loginUrl, string redirectUrl, CancellationToken cancellationToken = default); + } + + public enum BrowserStatus + { + Success, + UserCanceled, + Timeout, + UnknownError, + } + + public class BrowserResult + { + public BrowserStatus status { get; } + + public string callbackUrl { get; } + + public string error { get; } + + public BrowserResult(BrowserStatus status, string callbackUrl) + { + this.status = status; + this.callbackUrl = callbackUrl; + } + + public BrowserResult(BrowserStatus status, string callbackUrl, string error) + { + this.status = status; + this.callbackUrl = callbackUrl; + this.error = error; + } + } +} diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionError.cs.meta b/Assets/Thirdweb/Core/Scripts/Browser/IThirdwebBrowser.cs.meta similarity index 83% rename from Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionError.cs.meta rename to Assets/Thirdweb/Core/Scripts/Browser/IThirdwebBrowser.cs.meta index a84d3858..42302c11 100644 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionError.cs.meta +++ b/Assets/Thirdweb/Core/Scripts/Browser/IThirdwebBrowser.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b8dccbc4a08afe545b92ecbd6c6b39ad +guid: 1a3b9c6222dc7c74aa5efc60dbb95239 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/StandaloneBrowser.cs b/Assets/Thirdweb/Core/Scripts/Browser/StandaloneBrowser.cs similarity index 75% rename from Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/StandaloneBrowser.cs rename to Assets/Thirdweb/Core/Scripts/Browser/StandaloneBrowser.cs index 51d43e25..978a17c4 100644 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/StandaloneBrowser.cs +++ b/Assets/Thirdweb/Core/Scripts/Browser/StandaloneBrowser.cs @@ -1,23 +1,18 @@ -using System; +#if !UNITY_IOS && !UNITY_ANDROID + +using System; using System.Net; using System.Threading; using System.Threading.Tasks; using UnityEngine; -namespace Cdm.Authentication.Browser +namespace Thirdweb.Browser { - /// - /// OAuth 2.0 verification browser that runs a local server and waits for a call with - /// the authorization verification code. - /// - public class StandaloneBrowser : IBrowser + public class StandaloneBrowser : IThirdwebBrowser { private TaskCompletionSource _taskCompletionSource; - /// - /// Gets or sets the close page response. This HTML response is shown to the user after redirection is done. - /// - public string closePageResponse { get; set; } = + private readonly string closePageResponse = @" @@ -55,7 +50,7 @@ You can close this tab/window now. "; - public async Task StartAsync(string loginUrl, string redirectUrl, CancellationToken cancellationToken = default) + public async Task Login(string loginUrl, string redirectUrl, CancellationToken cancellationToken = default) { _taskCompletionSource = new TaskCompletionSource(); @@ -75,14 +70,14 @@ public async Task StartAsync(string loginUrl, string redirectUrl, Application.OpenURL(loginUrl); - var completedTask = await Task.WhenAny(_taskCompletionSource.Task, Task.Delay(TimeSpan.FromSeconds(60))); + var completedTask = await Task.WhenAny(_taskCompletionSource.Task, Task.Delay(TimeSpan.FromSeconds(30))); if (completedTask == _taskCompletionSource.Task) { return await _taskCompletionSource.Task; } else { - throw new TimeoutException("The operation timed out."); + return new BrowserResult(BrowserStatus.Timeout, null, "The operation timed out."); } } finally @@ -96,12 +91,9 @@ private void IncomingHttpRequest(IAsyncResult result) var httpListener = (HttpListener)result.AsyncState; var httpContext = httpListener.EndGetContext(result); var httpRequest = httpContext.Request; - - // Build a response to send an "ok" back to the browser for the user to see. var httpResponse = httpContext.Response; var buffer = System.Text.Encoding.UTF8.GetBytes(closePageResponse); - // Send the output to the client browser. httpResponse.ContentLength64 = buffer.Length; var output = httpResponse.OutputStream; output.Write(buffer, 0, buffer.Length); @@ -110,10 +102,6 @@ private void IncomingHttpRequest(IAsyncResult result) _taskCompletionSource.SetResult(new BrowserResult(BrowserStatus.Success, httpRequest.Url.ToString())); } - /// - /// Prefixes must end in a forward slash ("/") - /// - /// private string AddForwardSlashIfNecessary(string url) { string forwardSlash = "/"; @@ -121,8 +109,9 @@ private string AddForwardSlashIfNecessary(string url) { url += forwardSlash; } - return url; } } } + +#endif diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/StandaloneBrowser.cs.meta b/Assets/Thirdweb/Core/Scripts/Browser/StandaloneBrowser.cs.meta similarity index 83% rename from Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/StandaloneBrowser.cs.meta rename to Assets/Thirdweb/Core/Scripts/Browser/StandaloneBrowser.cs.meta index 0ea9f7c9..7594485f 100644 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/StandaloneBrowser.cs.meta +++ b/Assets/Thirdweb/Core/Scripts/Browser/StandaloneBrowser.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2c61cbaf114fbd949a5f0c69685383e1 +guid: 00ba92f3712145f409977bbfdafbe46d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Thirdweb/Core/Scripts/WalletsUI/EmbeddedWalletUI.cs b/Assets/Thirdweb/Core/Scripts/WalletsUI/EmbeddedWalletUI.cs index b02ff66e..07bea975 100644 --- a/Assets/Thirdweb/Core/Scripts/WalletsUI/EmbeddedWalletUI.cs +++ b/Assets/Thirdweb/Core/Scripts/WalletsUI/EmbeddedWalletUI.cs @@ -4,7 +4,7 @@ using UnityEngine.UI; using TMPro; using Thirdweb.Redcode.Awaiting; -using Cdm.Authentication.Browser; +using Thirdweb.Browser; using System.Web; using Newtonsoft.Json; using UnityEngine.Networking; @@ -26,7 +26,7 @@ public class EmbeddedWalletUI : MonoBehaviour private string _email; private User _user; private Exception _exception; - private string _redirectUrl; + private string _callbackUrl; private string _customScheme; private void Awake() @@ -41,8 +41,6 @@ private void Awake() Destroy(this.gameObject); return; } - - Application.deepLinkActivated += OnDeepLinkActivated; } public async Task Connect(EmbeddedWallet embeddedWallet, string email, bool useGoogle) @@ -130,18 +128,24 @@ private async Task LoginWithGoogle() try { string loginUrl = await GetLoginLink(); - OpenURL(loginUrl); + string redirectUrl = Application.isMobilePlatform ? _customScheme : "http://localhost:8789/"; + CrossPlatformBrowser browser = new(); + var browserResult = await browser.Login(loginUrl, redirectUrl); + if (browserResult.status != BrowserStatus.Success) + _exception = new UnityException($"Failed to login with Google: {browserResult.status} | {browserResult.error}"); + else + _callbackUrl = browserResult.callbackUrl; } - catch (System.Exception e) + catch (Exception e) { _exception = e; } - await new WaitUntil(() => _redirectUrl != null || _exception != null); + await new WaitUntil(() => _callbackUrl != null || _exception != null); if (_exception != null) throw _exception; - string decodedUrl = HttpUtility.UrlDecode(_redirectUrl); + string decodedUrl = HttpUtility.UrlDecode(_callbackUrl); Uri uri = new(decodedUrl); string queryString = uri.Query; var queryDict = HttpUtility.ParseQueryString(queryString); @@ -151,43 +155,6 @@ private async Task LoginWithGoogle() return user; } -#if UNITY_IOS - [DllImport("__Internal")] - private static extern void _OpenURL(string url); - - public void OpenURL(string url) - { - _OpenURL(url); - } -#elif UNITY_ANDROID - public void OpenURL(string url) - { - AndroidJavaClass thirdwebActivityClass = new("com.unity3d.player.UnityPlayer"); - AndroidJavaObject thirdwebActivity = thirdwebActivityClass.GetStatic("currentActivity"); - thirdwebActivity.Call("OpenCustomTab", url); - } -#else - public async void OpenURL(string url) - { - try - { - var standaloneBrowser = new StandaloneBrowser(); - var res = await standaloneBrowser.StartAsync(url, "http://localhost:8789/"); - _redirectUrl = res.redirectUrl; - } - catch (System.Exception e) - { - _exception = e; - } - } -#endif - - public void OnDeepLinkActivated(string url) - { - ThirdwebDebug.Log($"Received Link {url}"); - _redirectUrl = url; - } - private async Task GetLoginLink() { string platform = UnityWebRequest.EscapeURL("unity"); @@ -207,10 +174,5 @@ private async Task GetLoginLink() string developerClientId = UnityWebRequest.EscapeURL(ThirdwebManager.Instance.SDK.session.Options.clientId); return $"{loginUrl}?platform={platform}&redirectUrl={redirectUrl}&developerClientId={developerClientId}"; } - - private void OnDestroy() - { - Application.deepLinkActivated -= OnDeepLinkActivated; - } } } diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/CHANGELOG.md b/Assets/Thirdweb/Plugins/Authentication for Unity/CHANGELOG.md deleted file mode 100644 index abfe060f..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/CHANGELOG.md +++ /dev/null @@ -1,39 +0,0 @@ -# Changelog -All notable changes to this package will be documented in this file. - -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - -## [1.2.0] - 2023-07-02 -### Changes -- Added Authorization Code flow with PKCE (Proof Key for Code Exchange) `AuthorizationCodeFlowWithPkce`. - -## [1.1.3] - 2023-02-26 -### Changes -- Json serializable classes marked with `[Preserve]` attribute to prevent them from being stripped out (i.e. UWP platform) - -## [1.1.2] - 2023-02-1 -### Changes -- Redirect URL can be used without forward slash with `StandaloneBrowser` -- Added `DeepLinkBrowser` through a custom scheme (aka protocol) for Android, iOS, or UWP - -## [1.1.1] - 2022-12-16 -### Changes -- Added `csc.rsp` to fix `error CS0103: The name 'HttpUtility' does not exist in the current context` error - -## [1.1.0] - 2022-10-04 -### Changes -- Added `MockServer` to be able to test app against a mock oauth provider -- Fixed access token expiration comparison - -## [1.0.2] - 2022-09-28 -### Changes -- Bug fixes - -## [1.0.1] - 2022-09-27 -### Changes -- Added Facebook auth - -## [1.0.0] - 2022-09-27 -### Changes -- Initial release diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/CHANGELOG.md.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/CHANGELOG.md.meta deleted file mode 100644 index b6303508..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/CHANGELOG.md.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 3ed39218464c5bf4fbb9d942949b457d -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins.meta deleted file mode 100644 index 0ce81ab3..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 1f199ff994a9a644685b98f6457d7c54 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS.meta deleted file mode 100644 index 0fc88b07..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: bb272c91bec2239428314c7974931245 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/ASWebAuthenticationSession.mm b/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/ASWebAuthenticationSession.mm deleted file mode 100644 index 322a2324..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/ASWebAuthenticationSession.mm +++ /dev/null @@ -1,101 +0,0 @@ -#import - -#include "Common.h" - -extern UIViewController* UnityGetGLViewController(); - -typedef void (*ASWebAuthenticationSessionCompletionCallback)(void* sessionPtr, const char* callbackUrl, int errorCode, const char* errorMessage); - -@interface Cdm_ASWebAuthenticationSession : NSObject - -@property (readonly, nonatomic)ASWebAuthenticationSession* session; - -@end - -@implementation Cdm_ASWebAuthenticationSession - -- (instancetype)initWithURL:(NSURL *)URL callbackURLScheme:(nullable NSString *)callbackURLScheme completionCallback:(ASWebAuthenticationSessionCompletionCallback)completionCallback -{ - _session = [[ASWebAuthenticationSession alloc] initWithURL:URL - callbackURLScheme: callbackURLScheme - completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) - { - if (error != nil) - { - NSLog(@"[ASWebAuthenticationSession:CompletionHandler] %@", error.description); - } - else - { - //NSLog(@"[ASWebAuthenticationSession:CompletionHandler] Callback URL: %@", callbackURL); - } - - completionCallback((__bridge void*)self, toString(callbackURL.absoluteString), (int)error.code, toString(error.localizedDescription)); - }]; - - [_session setPresentationContextProvider:self]; - return self; -} - -- (nonnull ASPresentationAnchor)presentationAnchorForWebAuthenticationSession:(nonnull ASWebAuthenticationSession *)session -{ - #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000 - return [[[UIApplication sharedApplication] delegate] window]; - #elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 - return [[NSApplication sharedApplication] mainWindow]; - #else - return nil; - #endif -} - -@end - -extern "C" -{ - Cdm_ASWebAuthenticationSession* Cdm_Auth_ASWebAuthenticationSession_InitWithURL( - const char* urlStr, const char* urlSchemeStr, ASWebAuthenticationSessionCompletionCallback completionCallback) - { - //NSLog(@"[ASWebAuthenticationSession:InitWithURL] initWithURL: %s callbackURLScheme:%s", urlStr, urlSchemeStr); - - NSURL* url = [NSURL URLWithString: toString(urlStr)]; - NSString* urlScheme = toString(urlSchemeStr); - - Cdm_ASWebAuthenticationSession* session = [[Cdm_ASWebAuthenticationSession alloc] initWithURL:url - callbackURLScheme: urlScheme - completionCallback:completionCallback]; - return session; - } - - // Starts a web authentication session. - // https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession/2990953-start?language=objc - int Cdm_Auth_ASWebAuthenticationSession_Start(void* sessionPtr) - { - Cdm_ASWebAuthenticationSession* session = (__bridge Cdm_ASWebAuthenticationSession*) sessionPtr; - BOOL started = [[session session] start]; - - //NSLog(@"[ASWebAuthenticationSession:Start]: %s", (started ? "YES" : "NO")); - - return toBool(started); - } - - // Cancels a web authentication session. - // https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession/2990951-cancel?language=objc - void Cdm_Auth_ASWebAuthenticationSession_Cancel(void* sessionPtr) - { - //NSLog(@"[ASWebAuthenticationSession:Cancel]"); - - Cdm_ASWebAuthenticationSession* session = (__bridge Cdm_ASWebAuthenticationSession*) sessionPtr; - [[session session] cancel]; - } - - int Cdm_Auth_ASWebAuthenticationSession_GetPrefersEphemeralWebBrowserSession(void* sessionPtr) - { - Cdm_ASWebAuthenticationSession* session = (__bridge Cdm_ASWebAuthenticationSession*) sessionPtr; - return toBool([[session session] prefersEphemeralWebBrowserSession]); - } - - void Cdm_Auth_ASWebAuthenticationSession_SetPrefersEphemeralWebBrowserSession(void* sessionPtr, int enable) - { - Cdm_ASWebAuthenticationSession* session = (__bridge Cdm_ASWebAuthenticationSession*) sessionPtr; - [[session session] setPrefersEphemeralWebBrowserSession:toBool(enable)]; - } -} diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/ASWebAuthenticationSession.mm.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/ASWebAuthenticationSession.mm.meta deleted file mode 100644 index 6da52b03..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/ASWebAuthenticationSession.mm.meta +++ /dev/null @@ -1,85 +0,0 @@ -fileFormatVersion: 2 -guid: 07b283c1bd35f0e49a651150c1bee848 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 1 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - : Any - second: - enabled: 0 - settings: - Exclude Android: 1 - Exclude Editor: 1 - Exclude Linux64: 1 - Exclude OSXUniversal: 1 - Exclude Win: 1 - Exclude Win64: 1 - Exclude iOS: 0 - - first: - Android: Android - second: - enabled: 0 - settings: - CPU: ARMv7 - - first: - Any: - second: - enabled: 0 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - CPU: AnyCPU - DefaultValueInitialized: true - OS: AnyOS - - first: - Standalone: Linux64 - second: - enabled: 0 - settings: - CPU: x86_64 - - first: - Standalone: OSXUniversal - second: - enabled: 0 - settings: - CPU: None - - first: - Standalone: Win - second: - enabled: 0 - settings: - CPU: x86 - - first: - Standalone: Win64 - second: - enabled: 0 - settings: - CPU: x86_64 - - first: - iPhone: iOS - second: - enabled: 1 - settings: - AddToEmbeddedBinaries: false - CPU: AnyCPU - CompileFlags: - FrameworkDependencies: AuthenticationServices; - - first: - tvOS: tvOS - second: - enabled: 1 - settings: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/Common.h b/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/Common.h deleted file mode 100644 index d4a73fcb..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/Common.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef Common_h -#define Common_h - -typedef int bool_t; - -inline bool_t toBool(bool v) -{ - return v ? 1 : 0; -} - -inline bool toBool(bool_t v) -{ - return v != 0; -} - -inline NSString* toString(const char* string) -{ - if (string != NULL) - { - return [NSString stringWithUTF8String:string]; - } - else - { - return [NSString stringWithUTF8String:""]; - } -} - -inline char* toString(NSString* string) -{ - const char* cstr = [string UTF8String]; - - if (cstr == NULL) - return NULL; - - char* copy = (char*)malloc(strlen(cstr) + 1); - strcpy(copy, cstr); - return copy; -} - -#endif /* Common_h */ diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/Common.h.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/Common.h.meta deleted file mode 100644 index 7f5601d3..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/Common.h.meta +++ /dev/null @@ -1,27 +0,0 @@ -fileFormatVersion: 2 -guid: 62d11bbf6ff72c742a2c13d276bacaac -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 1 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - Any: - second: - enabled: 1 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/WKWebView.mm b/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/WKWebView.mm deleted file mode 100644 index b8b9baf8..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/WKWebView.mm +++ /dev/null @@ -1,266 +0,0 @@ -#import -#import - -#include "Common.h" - -extern UIViewController* UnityGetGLViewController(); - -typedef NS_ENUM(NSUInteger, WKWebViewAuthenticationSessionErrorCode) -{ - WKWebViewAuthenticationSessionErrorCodeNone = 0, - WKWebViewAuthenticationSessionErrorCodeCancelled = 1, - WKWebViewAuthenticationSessionErrorCodeOther = 2 -}; - -typedef void (*WKWebViewAuthenticationSessionCompletionCallback)(void* sessionPtr, const char* callbackUrl, int errorCode, const char* errorMessage); - -@interface WKWebViewAuthenticationSession : UIViewController -@end - -@implementation WKWebViewAuthenticationSession - -WKWebView* _webView; -NSURLRequest* _request; -NSString* _callbackUrlScheme; -BOOL _isCompletedSuccessfully; -BOOL _isDisposed; -BOOL _isViewDisappeared; -WKWebViewAuthenticationSessionCompletionCallback _completionCallback; - -- (instancetype)initWithURL:(NSURLRequest *)request callbackURLScheme:(nullable NSString *)callbackURLScheme completionCallback:(WKWebViewAuthenticationSessionCompletionCallback)completionCallback -{ - self = [super init]; - if(!self) return nil; - - _webView = nil; - _isCompletedSuccessfully = false; - _isDisposed = false; - _isViewDisappeared = false; - _request = request; - _callbackUrlScheme = callbackURLScheme; - _completionCallback = completionCallback; - return self; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - // Non persistent data store - private browsing. - WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; - configuration.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore]; - - _webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration]; - _webView.allowsLinkPreview = false; - _webView.navigationDelegate = self; - _webView.translatesAutoresizingMaskIntoConstraints = false; - - [self.view addSubview:_webView]; - - [NSLayoutConstraint activateConstraints:@[ - [self.view.leadingAnchor constraintEqualToAnchor:_webView.leadingAnchor], - [self.view.trailingAnchor constraintEqualToAnchor:_webView.trailingAnchor], - [self.view.topAnchor constraintEqualToAnchor:_webView.topAnchor], - [self.view.bottomAnchor constraintEqualToAnchor:_webView.bottomAnchor] - ]]; - - [_webView loadRequest:_request]; -} - -- (void)viewDidDisappear:(BOOL)animated -{ - [super viewDidDisappear:animated]; - - _isViewDisappeared = true; - - [self cancel]; -} - -- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler -{ - NSURL* url = [[navigationAction request] URL]; - if (url != nil) - { - //NSLog(@"[WKWebViewAuthenticationSession] decidePolicyForNavigationAction:%@", [url absoluteString]); - - NSURLComponents* urlComponents = [NSURLComponents componentsWithString:[url absoluteString]]; - - if (urlComponents != nil) - { - // If this is the OAuth callback, intercept it and feed it into the completion handler. - if ([self matchesCallbackUrl:urlComponents]) - { - NSLog(@"[WKWebViewAuthenticationSession] matchesCallbackUrl:YES"); - - _isCompletedSuccessfully = true; - decisionHandler(WKNavigationActionPolicyCancel); - - if (_completionCallback != nil) - { - _completionCallback((__bridge void*)self, toString([url absoluteString]), (int)WKWebViewAuthenticationSessionErrorCodeNone, nil); - } - - [self dispose]; - return; - } - } - } - - decisionHandler(WKNavigationActionPolicyAllow); -} - -- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error -{ - [self completeWithError:WKWebViewAuthenticationSessionErrorCodeOther withError:error]; -} - -- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error -{ - [self completeWithError:WKWebViewAuthenticationSessionErrorCodeOther withError:error]; -} - --(BOOL)matchesCallbackUrl:(NSURLComponents*)urlComponents -{ - if (_callbackUrlScheme != nil and urlComponents != nil) - { - return [[urlComponents scheme] isEqualToString:_callbackUrlScheme]; - } - - return false; -} - --(void)cancelButtonClicked:(UIButton*)sender -{ - NSLog(@"[WKWebViewAuthenticationSession] Cancelled login by pressing the 'Cancel' button."); - - [self cancel]; -} - --(BOOL)start -{ - if (_isDisposed) - { - NSLog(@"[WKWebViewAuthenticationSession] It was already disposed!"); - return false; - } - - if (_webView != nil) - { - NSLog(@"[WKWebViewAuthenticationSession] It was already started!"); - return false; - } - - self.modalPresentationStyle = UIModalPresentationPageSheet; - - UIViewController *unityViewController = UnityGetGLViewController(); - UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self]; - UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonClicked:)]; - self.navigationItem.rightBarButtonItem = cancelButton; - [unityViewController presentViewController:navigationController animated:YES completion:nil]; - - return true; -} - --(void)cancel -{ - NSError* error = [NSError errorWithDomain:@"User cancelled" code:(int)WKWebViewAuthenticationSessionErrorCodeCancelled userInfo:nil]; - - [self completeWithError:WKWebViewAuthenticationSessionErrorCodeCancelled withError:error]; -} - -- (void)dispose -{ - if (_isDisposed) - return; - - _isDisposed = true; - - UIViewController *unityViewController = UnityGetGLViewController(); - if (unityViewController != nil && !_isViewDisappeared) - { - [unityViewController dismissViewControllerAnimated:YES completion:^(){ [self destroyWebView]; }]; - } - else - { - [self destroyWebView]; - } -} - -- (void)destroyWebView -{ - WKWebView* webViewTemp = _webView; - _webView = nil; - - if (webViewTemp != nil) - { - webViewTemp.UIDelegate = nil; - webViewTemp.navigationDelegate = nil; - - [webViewTemp stopLoading]; - [webViewTemp removeFromSuperview]; - } -} - -- (void)completeWithError:(WKWebViewAuthenticationSessionErrorCode)errorCode withError:(NSError*)error -{ - if (!_isCompletedSuccessfully && !_isDisposed) - { - if (_completionCallback != nil) - { - _completionCallback((__bridge void*)self, nil, (int)errorCode, toString(error.localizedDescription)); - } - - [self dispose]; - } -} - -@end - -extern "C" -{ - WKWebViewAuthenticationSession* Cdm_Auth_WKWebViewAuthenticationSession_Init(const char* urlStr, const char* urlScheme, - WKWebViewAuthenticationSessionCompletionCallback completionCallback) - { - //NSLog(@"[WKWebViewAuthenticationSession:Init] [url:%s] [scheme:%s]", urlStr, urlScheme); - - NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: toString(urlStr)]]; - - WKWebViewAuthenticationSession* session = - [[WKWebViewAuthenticationSession alloc] initWithURL:request callbackURLScheme:toString(urlScheme) completionCallback:completionCallback]; - - return session; - } - - int Cdm_Auth_WKWebViewAuthenticationSession_Start(void* sessionPtr) - { - //NSLog(@"[WKWebViewAuthenticationSession:Start]"); - - if (sessionPtr == NULL) - return toBool(false); - - WKWebViewAuthenticationSession* session = (__bridge WKWebViewAuthenticationSession*) sessionPtr; - return toBool([session start]); - } - - void Cdm_Auth_WKWebViewAuthenticationSession_Cancel(void* sessionPtr) - { - //NSLog(@"[WKWebViewAuthenticationSession:Cancel]"); - - if (sessionPtr == NULL) - return; - - WKWebViewAuthenticationSession *session = (__bridge WKWebViewAuthenticationSession *)sessionPtr; - [session cancel]; - } - - void Cdm_Auth_WKWebViewAuthenticationSession_Dispose(void* sessionPtr) - { - //NSLog(@"[WKWebViewAuthenticationSession:Dispose]"); - - if (sessionPtr == NULL) - return; - - WKWebViewAuthenticationSession *session = (__bridge WKWebViewAuthenticationSession *)sessionPtr; - [session dispose]; - } -} diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/WKWebView.mm.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/WKWebView.mm.meta deleted file mode 100644 index 44339c01..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Plugins/iOS/WKWebView.mm.meta +++ /dev/null @@ -1,85 +0,0 @@ -fileFormatVersion: 2 -guid: ef449615493c13a4f825af46acdcb5f6 -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 1 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - : Any - second: - enabled: 0 - settings: - Exclude Android: 1 - Exclude Editor: 1 - Exclude Linux64: 1 - Exclude OSXUniversal: 1 - Exclude Win: 1 - Exclude Win64: 1 - Exclude iOS: 0 - - first: - Android: Android - second: - enabled: 0 - settings: - CPU: ARMv7 - - first: - Any: - second: - enabled: 0 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - CPU: AnyCPU - DefaultValueInitialized: true - OS: AnyOS - - first: - Standalone: Linux64 - second: - enabled: 0 - settings: - CPU: AnyCPU - - first: - Standalone: OSXUniversal - second: - enabled: 0 - settings: - CPU: None - - first: - Standalone: Win - second: - enabled: 0 - settings: - CPU: x86 - - first: - Standalone: Win64 - second: - enabled: 0 - settings: - CPU: x86_64 - - first: - iPhone: iOS - second: - enabled: 1 - settings: - AddToEmbeddedBinaries: false - CPU: AnyCPU - CompileFlags: - FrameworkDependencies: WebKit; - - first: - tvOS: tvOS - second: - enabled: 1 - settings: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/README.md b/Assets/Thirdweb/Plugins/Authentication for Unity/README.md deleted file mode 100644 index 1e0ae805..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# Authentication Package for Unity -- OAuth2 - - Authorization code flow (https://www.rfc-editor.org/rfc/rfc6749#section-4.1) - - Authorization code flow with PKCE (Proof Key for Code Exchange) (https://www.rfc-editor.org/rfc/rfc7636) -- Built-in clients - - GitHub - - Google - - Facebook -- Built-in browser support - - Deep link browser (iOS, Android, Universal Windows Platform and macOS) (https://docs.unity3d.com/Manual/deep-linking.html) - - Standalone as local server (Windows, macOS and Linux) - - ASWebAuthenticationSession (iOS) (https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession) - - WKWebView (iOS) (https://developer.apple.com/documentation/webkit/wkwebview) - -## Install via Unity Package Manager: -* Add `"com.cdm.authentication": "https://github.com/cdmvision/authentication-unity.git#1.2.0"` to your project's package manifest file in dependencies section. -* Or, `Package Manager > Add package from git URL...` and paste this URL: `https://github.com/cdmvision/authentication-unity.git#1.2.0` - -## Example usage - -You should create your client auth configuration: -```csharp -// Also you can use your own client configuration. -var auth = new GoogleAuth() -{ - clientId = "...", - redirectUrl = "...", - scope = "openid email profile" -}; -``` - -Authentication session is created with auth configuration and a browser: -```csharp -using var authenticationSession = new AuthenticationSession(auth, new StandaloneBrowser()); -``` - -Also you can use different browsers for each platform by using cross platform browser: -```csharp -var crossPlatformBrowser = new CrossPlatformBrowser(); -var crossPlatformBrowser.platformBrowsers.Add(RuntimePlatform.WindowsEditor, new StandaloneBrowser()); -var crossPlatformBrowser.platformBrowsers.Add(RuntimePlatform.WindowsPlayer, new StandaloneBrowser()); -var crossPlatformBrowser.platformBrowsers.Add(RuntimePlatform.OSXEditor, new StandaloneBrowser()); -var crossPlatformBrowser.platformBrowsers.Add(RuntimePlatform.OSXPlayer, new StandaloneBrowser()); -var crossPlatformBrowser.platformBrowsers.Add(RuntimePlatform.IPhonePlayer, new ASWebAuthenticationSessionBrowser()); - -using var authenticationSession = new AuthenticationSession(auth, crossPlatformBrowser); - -// Opens a browser to log user in -AccessTokenResponse accessTokenResponse = await authenticationSession.AuthenticateAsync(); - -// Authentication header can be used to make authorized http calls. -AuthenticationHeaderValue authenticationHeader = accessTokenResponse.GetAuthenticationHeader(); - -// Gets the current acccess token, or refreshes if it is expired. -accessTokenResponse = await authenticationSession.GetOrRefreshTokenAsync(); - -// Gets new access token by using the refresh token. -AccessTokenResponse newAccessTokenResponse = await authenticationSession.RefreshTokenAsync(); - -// Or you can get new access token with specified refresh token (i.e. stored on the local disk to prevent multiple sign-in for each app launch) -newAccessTokenResponse = await authenticationSession.RefreshTokenAsync("my_refresh_token"); -``` diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/README.md.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/README.md.meta deleted file mode 100644 index 118bb957..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/README.md.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 25d5647e6955328458d19bf266b41394 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime.meta deleted file mode 100644 index 6d0476ae..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 86e9d5a461a78e84481a8e68c2bf7126 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser.meta deleted file mode 100644 index f046b4b4..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d67c4ef8cef3fd549af82e76f2275746 -timeCreated: 1663713639 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSession.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSession.cs deleted file mode 100644 index 3735c6a7..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSession.cs +++ /dev/null @@ -1,142 +0,0 @@ -using System; -using System.Collections.Generic; -using AOT; - -#if UNITY_IOS && !UNITY_EDITOR -using System.Runtime.InteropServices; -#endif - -namespace Cdm.Authentication.Browser -{ - /// - /// A session that an app uses to authenticate a user through a web service. - /// - /// - public class ASWebAuthenticationSession : IDisposable - { - private static readonly Dictionary CompletionCallbacks = - new Dictionary(); - - private IntPtr _sessionPtr; - - /// - /// A Boolean value that indicates whether the session should ask the browser for a private authentication - /// session. - /// - /// Set this property before you call . Otherwise it has no effect. - public bool prefersEphemeralWebBrowserSession - { - get => Cdm_Auth_ASWebAuthenticationSession_GetPrefersEphemeralWebBrowserSession(_sessionPtr) == 1; - set => Cdm_Auth_ASWebAuthenticationSession_SetPrefersEphemeralWebBrowserSession(_sessionPtr, value ? 1 : 0); - } - - /// - /// Creates a web authentication session instance. - /// - /// A URL with the http or https scheme pointing to the authentication webpage. - /// The custom URL scheme that the app expects in the callback URL. - /// A completion handler the session calls when it completes successfully, or when the user cancels the session. - /// - public ASWebAuthenticationSession(string url, string callbackUrlScheme, - ASWebAuthenticationSessionCompletionHandler completionHandler) - { - _sessionPtr = - Cdm_Auth_ASWebAuthenticationSession_InitWithURL( - url, callbackUrlScheme, OnAuthenticationSessionCompleted); - - CompletionCallbacks.Add(_sessionPtr, completionHandler); - } - - /// - /// Starts a web authentication session. - /// - /// A Boolean value indicating whether the web authentication session started successfully. - /// - public bool Start() - { - return Cdm_Auth_ASWebAuthenticationSession_Start(_sessionPtr) == 1; - } - - /// - /// Cancels a web authentication session. - /// - /// - public void Cancel() - { - Cdm_Auth_ASWebAuthenticationSession_Cancel(_sessionPtr); - } - - public void Dispose() - { - CompletionCallbacks.Remove(_sessionPtr); - _sessionPtr = IntPtr.Zero; - } - -#if UNITY_IOS && !UNITY_EDITOR - private const string DllName = "__Internal"; - - [DllImport(DllName)] - private static extern IntPtr Cdm_Auth_ASWebAuthenticationSession_InitWithURL( - string url, string callbackUrlScheme, AuthenticationSessionCompletedCallback completionHandler); - - [DllImport(DllName)] - private static extern int Cdm_Auth_ASWebAuthenticationSession_Start(IntPtr session); - - [DllImport(DllName)] - private static extern void Cdm_Auth_ASWebAuthenticationSession_Cancel(IntPtr session); - - [DllImport(DllName)] - private static extern int Cdm_Auth_ASWebAuthenticationSession_GetPrefersEphemeralWebBrowserSession(IntPtr session); - - [DllImport(DllName)] - private static extern void Cdm_Auth_ASWebAuthenticationSession_SetPrefersEphemeralWebBrowserSession( - IntPtr session, int enable); -#else - - private const string NotSupportedMsg = "Only iOS platform is supported."; - - private static IntPtr Cdm_Auth_ASWebAuthenticationSession_InitWithURL( - string url, string callbackUrlScheme, AuthenticationSessionCompletedCallback completionHandler) - { - throw new NotImplementedException(NotSupportedMsg); - } - - private static int Cdm_Auth_ASWebAuthenticationSession_Start(IntPtr session) - { - throw new NotImplementedException(NotSupportedMsg); - } - - private static void Cdm_Auth_ASWebAuthenticationSession_Cancel(IntPtr session) - { - throw new NotImplementedException(NotSupportedMsg); - } - - private static int Cdm_Auth_ASWebAuthenticationSession_GetPrefersEphemeralWebBrowserSession(IntPtr session) - { - throw new NotImplementedException(NotSupportedMsg); - } - - private static void Cdm_Auth_ASWebAuthenticationSession_SetPrefersEphemeralWebBrowserSession( - IntPtr session, int enable) - { - throw new NotImplementedException(NotSupportedMsg); - } -#endif - public delegate void ASWebAuthenticationSessionCompletionHandler(string callbackUrl, - ASWebAuthenticationSessionError error); - - private delegate void AuthenticationSessionCompletedCallback(IntPtr session, string callbackUrl, - int errorCode, string errorMessage); - - [MonoPInvokeCallback(typeof(AuthenticationSessionCompletedCallback))] - private static void OnAuthenticationSessionCompleted(IntPtr session, string callbackUrl, - int errorCode, string errorMessage) - { - if (CompletionCallbacks.TryGetValue(session, out var callback)) - { - callback?.Invoke(callbackUrl, - new ASWebAuthenticationSessionError((ASWebAuthenticationSessionErrorCode) errorCode, errorMessage)); - } - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionBrowser.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionBrowser.cs deleted file mode 100644 index 3f327f56..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionBrowser.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Cdm.Authentication.Browser -{ - public class ASWebAuthenticationSessionBrowser : IBrowser - { - private TaskCompletionSource _taskCompletionSource; - - /// - /// Indicates whether the session should ask the browser for a private authentication - /// session. - /// - /// - /// Set this property before you call . Otherwise it has no effect. - /// - public bool prefersEphemeralWebBrowserSession { get; set; } = false; - - public async Task StartAsync( - string loginUrl, string redirectUrl, CancellationToken cancellationToken = default) - { - if (string.IsNullOrEmpty(loginUrl)) - throw new ArgumentNullException(nameof(loginUrl)); - - if (string.IsNullOrEmpty(redirectUrl)) - throw new ArgumentNullException(nameof(redirectUrl)); - - _taskCompletionSource = new TaskCompletionSource(); - - // Discard URL parameters. They are not valid for iOS URL Scheme. - redirectUrl = redirectUrl.Split(new char[] {':'}, StringSplitOptions.RemoveEmptyEntries)[0]; - - using var authenticationSession = - new ASWebAuthenticationSession(loginUrl, redirectUrl, AuthenticationSessionCompletionHandler); - authenticationSession.prefersEphemeralWebBrowserSession = prefersEphemeralWebBrowserSession; - - cancellationToken.Register(() => - { - _taskCompletionSource?.TrySetCanceled(); - }); - - try - { - if (!authenticationSession.Start()) - { - _taskCompletionSource.SetResult( - new BrowserResult(BrowserStatus.UnknownError, "Browser could not be started.")); - } - - return await _taskCompletionSource.Task; - } - catch (TaskCanceledException) - { - // In case of timeout cancellation. - authenticationSession?.Cancel(); - throw; - } - } - - private void AuthenticationSessionCompletionHandler(string callbackUrl, ASWebAuthenticationSessionError error) - { - if (error.code == ASWebAuthenticationSessionErrorCode.None) - { - _taskCompletionSource.SetResult( - new BrowserResult(BrowserStatus.Success, callbackUrl)); - } - else if (error.code == ASWebAuthenticationSessionErrorCode.CanceledLogin) - { - _taskCompletionSource.SetResult( - new BrowserResult(BrowserStatus.UserCanceled, callbackUrl, error.message)); - } - else - { - _taskCompletionSource.SetResult( - new BrowserResult(BrowserStatus.UnknownError, callbackUrl, error.message)); - } - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionError.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionError.cs deleted file mode 100644 index 9d6042dd..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionError.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Cdm.Authentication.Browser -{ - public class ASWebAuthenticationSessionError - { - public ASWebAuthenticationSessionErrorCode code { get; } - public string message { get; } - - public ASWebAuthenticationSessionError(ASWebAuthenticationSessionErrorCode code, string message) - { - this.code = code; - this.message = message; - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionErrorCode.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionErrorCode.cs deleted file mode 100644 index d6b9526b..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionErrorCode.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Cdm.Authentication.Browser -{ - public enum ASWebAuthenticationSessionErrorCode - { - None = 0, - CanceledLogin = 1, - PresentationContextNotProvided = 2, - PresentationContextInvalid = 3 - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionErrorCode.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionErrorCode.cs.meta deleted file mode 100644 index f5d880a0..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/ASWebAuthenticationSessionErrorCode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d599b007b73c65b47930262ce0dc0d9b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserResult.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserResult.cs deleted file mode 100644 index b279e2fc..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserResult.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace Cdm.Authentication.Browser -{ - public class BrowserResult - { - /// - /// The browser status indicates the operation is whether success or not. - /// - public BrowserStatus status { get; } - - /// - /// After a user successfully authorizes an application, the authorization server will redirect the user back - /// to the application with the redirect URL. Use this if only if is - /// . - /// - public string redirectUrl { get; } - - /// - /// The error description if an error is exist. You can use this value if is not - /// . - /// - public string error { get; } - - public BrowserResult(BrowserStatus status, string redirectUrl) - { - this.status = status; - this.redirectUrl = redirectUrl; - } - - public BrowserResult(BrowserStatus status, string redirectUrl, string error) - { - this.status = status; - this.redirectUrl = redirectUrl; - this.error = error; - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserResult.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserResult.cs.meta deleted file mode 100644 index bef2f986..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserResult.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8addf7d9c8e305b49a1133df23d74c0b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserStatus.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserStatus.cs deleted file mode 100644 index 8bb22154..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserStatus.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cdm.Authentication.Browser -{ - public enum BrowserStatus - { - Success, - UserCanceled, - UnknownError, - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserStatus.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserStatus.cs.meta deleted file mode 100644 index 8177a043..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/BrowserStatus.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5931c5eb5bc29104c8b21e747e063df0 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/CrossPlatformBrowser.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/CrossPlatformBrowser.cs deleted file mode 100644 index f5443846..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/CrossPlatformBrowser.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using UnityEngine; - -namespace Cdm.Authentication.Browser -{ - public class CrossPlatformBrowser : IBrowser - { - public readonly Dictionary _platformBrowsers = - new Dictionary(); - - public IDictionary platformBrowsers => _platformBrowsers; - - public async Task StartAsync( - string loginUrl, string redirectUrl, CancellationToken cancellationToken = default) - { - var browser = platformBrowsers.FirstOrDefault(x => x.Key == Application.platform).Value; - if (browser == null) - throw new NotSupportedException($"There is no browser found for '{Application.platform}' platform."); - - return await browser.StartAsync(loginUrl, redirectUrl, cancellationToken); - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/DeepLinkBrowser.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/DeepLinkBrowser.cs deleted file mode 100644 index 5fef5067..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/DeepLinkBrowser.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; -using UnityEngine; - -namespace Cdm.Authentication.Browser -{ - /// - /// OAuth 2.0 verification browser that waits for a call with - /// the authorization verification code through a custom scheme (aka protocol). - /// - /// - public class DeepLinkBrowser : IBrowser - { - private TaskCompletionSource _taskCompletionSource; - - public async Task StartAsync(string loginUrl, string redirectUrl, CancellationToken cancellationToken = default) - { - _taskCompletionSource = new TaskCompletionSource(); - - cancellationToken.Register(() => - { - _taskCompletionSource?.TrySetCanceled(); - }); - - Application.deepLinkActivated += OnDeepLinkActivated; - - try - { - Application.OpenURL(loginUrl); - return await _taskCompletionSource.Task; - } - finally - { - Application.deepLinkActivated -= OnDeepLinkActivated; - } - } - - private void OnDeepLinkActivated(string url) - { - _taskCompletionSource.SetResult( - new BrowserResult(BrowserStatus.Success, url)); - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/DeepLinkBrowser.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/DeepLinkBrowser.cs.meta deleted file mode 100644 index da769dfb..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/DeepLinkBrowser.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fb5adf8e686cdea44a9778f99d6a06f5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/IBrowser.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/IBrowser.cs deleted file mode 100644 index 05de1613..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/IBrowser.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; - -namespace Cdm.Authentication.Browser -{ - public interface IBrowser - { - Task StartAsync( - string loginUrl, string redirectUrl, CancellationToken cancellationToken = default); - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/IBrowser.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/IBrowser.cs.meta deleted file mode 100644 index 595a592e..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/IBrowser.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b8b531b949edf2049a13cf038b476919 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSession.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSession.cs deleted file mode 100644 index b88d6bbd..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSession.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.Collections.Generic; -using AOT; - -#if UNITY_IOS && !UNITY_EDITOR -using System.Runtime.InteropServices; -#endif - -namespace Cdm.Authentication.Browser -{ - public class WKWebViewAuthenticationSession : IDisposable - { - private static readonly Dictionary - CompletionCallbacks = new Dictionary(); - - private IntPtr _sessionPtr; - - public WKWebViewAuthenticationSession(string url, string callbackUrlScheme, - WKWebViewAuthenticationSessionCompletionHandler completionHandler) - { - _sessionPtr = Cdm_Auth_WKWebViewAuthenticationSession_Init( - url, callbackUrlScheme, OnAuthenticationSessionCompleted); - - CompletionCallbacks.Add(_sessionPtr, completionHandler); - } - - public bool Start() - { - return Cdm_Auth_WKWebViewAuthenticationSession_Start(_sessionPtr) == 1; - } - - public void Cancel() - { - Cdm_Auth_WKWebViewAuthenticationSession_Cancel(_sessionPtr); - } - - public void Dispose() - { - Cdm_Auth_WKWebViewAuthenticationSession_Dispose(_sessionPtr); - CompletionCallbacks.Remove(_sessionPtr); - _sessionPtr = IntPtr.Zero; - } - -#if UNITY_IOS && !UNITY_EDITOR - private const string DllName = "__Internal"; - - [DllImport(DllName)] - private static extern IntPtr Cdm_Auth_WKWebViewAuthenticationSession_Init(string url, string callbackUrlScheme, - AuthenticationSessionCompletedCallback completionHandler); - - [DllImport(DllName)] - private static extern int Cdm_Auth_WKWebViewAuthenticationSession_Start(IntPtr session); - - [DllImport(DllName)] - private static extern void Cdm_Auth_WKWebViewAuthenticationSession_Cancel(IntPtr session); - - [DllImport(DllName)] - private static extern void Cdm_Auth_WKWebViewAuthenticationSession_Dispose(IntPtr session); -#else - private const string NotSupportedMsg = "Only iOS platform is supported."; - - private static IntPtr Cdm_Auth_WKWebViewAuthenticationSession_Init(string url, string callbackUrlScheme, - AuthenticationSessionCompletedCallback completionHandler) - { - throw new NotImplementedException(NotSupportedMsg); - } - - private static int Cdm_Auth_WKWebViewAuthenticationSession_Start(IntPtr session) - { - throw new NotImplementedException(NotSupportedMsg); - } - - private static void Cdm_Auth_WKWebViewAuthenticationSession_Cancel(IntPtr session) - { - throw new NotImplementedException(NotSupportedMsg); - } - - private static void Cdm_Auth_WKWebViewAuthenticationSession_Dispose(IntPtr session) - { - } -#endif - - public delegate void WKWebViewAuthenticationSessionCompletionHandler(string callbackUrl, - WKWebViewAuthenticationSessionError error); - - private delegate void AuthenticationSessionCompletedCallback(IntPtr session, string callbackUrl, - int errorCode, string errorMessage); - - [MonoPInvokeCallback(typeof(AuthenticationSessionCompletedCallback))] - private static void OnAuthenticationSessionCompleted(IntPtr session, string callbackUrl, - int errorCode, string errorMessage) - { - if (CompletionCallbacks.TryGetValue(session, out var callback)) - { - callback?.Invoke(callbackUrl, - new WKWebViewAuthenticationSessionError((WKWebViewAuthenticationSessionErrorCode)errorCode, - errorMessage)); - } - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSession.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSession.cs.meta deleted file mode 100644 index 339f8dcc..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSession.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d7afdfad95bb2b94e94c737454147eb6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionBrowser.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionBrowser.cs deleted file mode 100644 index 897801a0..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionBrowser.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; - -namespace Cdm.Authentication.Browser -{ - public class WKWebViewAuthenticationSessionBrowser : IBrowser - { - private TaskCompletionSource _taskCompletionSource; - - public async Task StartAsync( - string loginUrl, string redirectUrl, CancellationToken cancellationToken = default) - { - if (string.IsNullOrEmpty(loginUrl)) - throw new ArgumentNullException(nameof(loginUrl)); - - if (string.IsNullOrEmpty(redirectUrl)) - throw new ArgumentNullException(nameof(redirectUrl)); - - _taskCompletionSource = new TaskCompletionSource(); - - // Discard URL parameters. They are not valid for iOS URL Scheme. - redirectUrl = redirectUrl.Split(new char[] {':'}, StringSplitOptions.RemoveEmptyEntries)[0]; - - using var authenticationSession = - new WKWebViewAuthenticationSession(loginUrl, redirectUrl, AuthenticationSessionCompletionHandler); - - cancellationToken.Register(() => { _taskCompletionSource?.TrySetCanceled(); }); - - try - { - if (!authenticationSession.Start()) - { - _taskCompletionSource.SetResult( - new BrowserResult(BrowserStatus.UnknownError, "Browser could not be started.")); - } - - return await _taskCompletionSource.Task; - } - catch (TaskCanceledException) - { - // In case of timeout cancellation. - authenticationSession?.Cancel(); - throw; - } - } - - private void AuthenticationSessionCompletionHandler(string callbackUrl, - WKWebViewAuthenticationSessionError error) - { - if (error.code == WKWebViewAuthenticationSessionErrorCode.None) - { - _taskCompletionSource.SetResult( - new BrowserResult(BrowserStatus.Success, callbackUrl)); - } - else if (error.code == WKWebViewAuthenticationSessionErrorCode.CanceledLogin) - { - _taskCompletionSource.SetResult( - new BrowserResult(BrowserStatus.UserCanceled, callbackUrl, error.message)); - } - else - { - _taskCompletionSource.SetResult( - new BrowserResult(BrowserStatus.UnknownError, callbackUrl, error.message)); - } - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionBrowser.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionBrowser.cs.meta deleted file mode 100644 index 3b5c9fba..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionBrowser.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d46e9b62646c3814585a3fe4bdc02a4f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionError.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionError.cs deleted file mode 100644 index c856626c..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionError.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Cdm.Authentication.Browser -{ - public class WKWebViewAuthenticationSessionError - { - public WKWebViewAuthenticationSessionErrorCode code { get; } - public string message { get; } - - public WKWebViewAuthenticationSessionError(WKWebViewAuthenticationSessionErrorCode code, string message) - { - this.code = code; - this.message = message; - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionError.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionError.cs.meta deleted file mode 100644 index 091f7894..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionError.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: ba117fecc64ccec4c91220a2bd4614f4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionErrorCode.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionErrorCode.cs deleted file mode 100644 index 390aaab6..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionErrorCode.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cdm.Authentication.Browser -{ - public enum WKWebViewAuthenticationSessionErrorCode - { - None = 0, - CanceledLogin = 1, - Other = 2 - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionErrorCode.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionErrorCode.cs.meta deleted file mode 100644 index df4c2561..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Browser/WKWebViewAuthenticationSessionErrorCode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5cf8d8b7673155442ae4f2ac273545ae -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients.meta deleted file mode 100644 index ddca2a81..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 726cb98b70d79664f954982869826c2a -timeCreated: 1663712970 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/FacebookAuth.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/FacebookAuth.cs deleted file mode 100644 index 9e49db26..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/FacebookAuth.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System.Runtime.Serialization; -using System.Threading; -using System.Threading.Tasks; -using Cdm.Authentication.OAuth2; -using Cdm.Authentication.Utils; - -namespace Cdm.Authentication.Clients -{ - public class FacebookAuth : AuthorizationCodeFlow, IUserInfoProvider - { - public override string authorizationUrl => "https://www.facebook.com/dialog/oauth"; - public override string accessTokenUrl => "https://graph.facebook.com/oauth/access_token"; - public string userInfoUrl => "https://graph.facebook.com/me"; - - public FacebookAuth(Configuration configuration) : base(configuration) - { - } - - public async Task GetUserInfoAsync(CancellationToken cancellationToken = default) - { - if (accessTokenResponse == null) - throw new AccessTokenRequestException(new AccessTokenRequestError() - { - code = AccessTokenRequestErrorCode.InvalidGrant, - description = "Authentication required." - }, null); - - var authenticationHeader = accessTokenResponse.GetAuthenticationHeader(); - return await UserInfoParser.GetUserInfoAsync( - httpClient, userInfoUrl, authenticationHeader, cancellationToken); - } - } - - [DataContract] - public class FacebookUserInfo : IUserInfo - { - [DataMember(Name = "id", IsRequired = true)] - public string id { get; set; } - - [DataMember(Name = "first_name")] - public string firstName { get; set; } - - [DataMember(Name = "last_name")] - public string lastName { get; set; } - - [DataMember(Name = "email")] - public string email { get; set; } - - [DataMember(Name = "picture")] - public PictureData pictureData { get; set; } - - public string name => $"{firstName} {lastName}"; - public string picture => pictureData?.url; - - [DataContract] - public class PictureData - { - [DataMember(Name = "url", IsRequired = true)] - public string url { get; set; } - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/FacebookAuth.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/FacebookAuth.cs.meta deleted file mode 100644 index 32d3454b..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/FacebookAuth.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d485c72379fb6504caeacb2e0e60d17b -timeCreated: 1664278487 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GitHubAuth.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GitHubAuth.cs deleted file mode 100644 index 35f6681b..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GitHubAuth.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Runtime.Serialization; -using System.Threading; -using System.Threading.Tasks; -using Cdm.Authentication.OAuth2; -using Cdm.Authentication.Utils; - -namespace Cdm.Authentication.Clients -{ - public class GitHubAuth : AuthorizationCodeFlow, IUserInfoProvider - { - public GitHubAuth(Configuration configuration) : base(configuration) - { - } - - public override string authorizationUrl => "https://github.com/login/oauth/authorize"; - public override string accessTokenUrl => "https://github.com/login/oauth/access_token"; - public string userInfoUrl => "https://www.googleapis.com/oauth2/v1/userinfo"; - - public async Task GetUserInfoAsync(CancellationToken cancellationToken = default) - { - if (accessTokenResponse == null) - throw new AccessTokenRequestException(new AccessTokenRequestError() - { - code = AccessTokenRequestErrorCode.InvalidGrant, - description = "Authentication required." - }, null); - - var authenticationHeader = accessTokenResponse.GetAuthenticationHeader(); - return await UserInfoParser.GetUserInfoAsync( - httpClient, userInfoUrl, authenticationHeader, cancellationToken); - } - } - - [DataContract] - public class GitHubUserInfo : IUserInfo - { - [DataMember(Name = "id", IsRequired = true)] - public string id { get; set; } - - [DataMember(Name = "name")] - public string name { get; set; } - - [DataMember(Name = "email")] - public string email { get; set; } - - [DataMember(Name = "avatar_url")] - public string avatarUrl { get; set; } - - public string picture => avatarUrl; - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GitHubAuth.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GitHubAuth.cs.meta deleted file mode 100644 index 2cec2309..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GitHubAuth.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0d3b3c6de2a0eb2429009cc241e3fd4e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GoogleAuth.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GoogleAuth.cs deleted file mode 100644 index 9fcc5b33..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GoogleAuth.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System.Runtime.Serialization; -using System.Threading; -using System.Threading.Tasks; -using Cdm.Authentication.OAuth2; -using Cdm.Authentication.Utils; - -namespace Cdm.Authentication.Clients -{ - public class GoogleAuth : AuthorizationCodeFlow, IUserInfoProvider - { - public GoogleAuth(Configuration configuration) : base(configuration) - { - } - - public override string authorizationUrl => "https://accounts.google.com/o/oauth2/auth"; - public override string accessTokenUrl => "https://accounts.google.com/o/oauth2/token"; - public string userInfoUrl => "https://www.googleapis.com/oauth2/v1/userinfo"; - - public async Task GetUserInfoAsync(CancellationToken cancellationToken = default) - { - if (accessTokenResponse == null) - throw new AccessTokenRequestException(new AccessTokenRequestError() - { - code = AccessTokenRequestErrorCode.InvalidGrant, - description = "Authentication required." - }, null); - - var authenticationHeader = accessTokenResponse.GetAuthenticationHeader(); - return await UserInfoParser.GetUserInfoAsync( - httpClient, userInfoUrl, authenticationHeader, cancellationToken); - } - } - - [DataContract] - public class GoogleUserInfo : IUserInfo - { - [DataMember(Name = "id", IsRequired = true)] - public string id { get; set; } - - [DataMember(Name = "name")] - public string name { get; set; } - - [DataMember(Name = "given_name")] - public string givenName { get; set; } - - [DataMember(Name = "family_name")] - public string familyName { get; set; } - - [DataMember(Name = "email")] - public string email { get; set; } - - [DataMember(Name = "picture")] - public string picture { get; set; } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GoogleAuth.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GoogleAuth.cs.meta deleted file mode 100644 index 790e8486..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/GoogleAuth.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 85d5f38236326c74a81697502469b137 -timeCreated: 1663798556 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/MockServerAuth.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/MockServerAuth.cs deleted file mode 100644 index 77a0d3b9..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/MockServerAuth.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Cdm.Authentication.OAuth2; - -namespace Cdm.Authentication.Clients -{ - public class MockServerAuth : AuthorizationCodeFlow - { - public const string AuthorizationPath = "/oauth/authorize"; - public const string TokenPath = "/oauth/token"; - - public override string authorizationUrl => $"{serverUrl}{AuthorizationPath}"; - public override string accessTokenUrl => $"{serverUrl}{TokenPath}"; - - public string serverUrl { get; } - - public MockServerAuth(Configuration configuration, string serverUrl) : base(configuration) - { - this.serverUrl = serverUrl; - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/MockServerAuth.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/MockServerAuth.cs.meta deleted file mode 100644 index c3d7a8b1..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Clients/MockServerAuth.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 8be79a8411cba4b4bbd18c2e6c1295c5 -timeCreated: 1664364081 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfo.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfo.cs deleted file mode 100644 index 7e663470..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfo.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Cdm.Authentication -{ - public interface IUserInfo - { - /// - /// Gets the user identifier. - /// - public string id { get; } - - /// - /// Gets the name of the user. - /// - public string name { get; } - - /// - /// Gets the email address of the user. - /// - public string email { get; } - - /// - /// Gets the user picture URL. - /// - public string picture { get; } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfo.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfo.cs.meta deleted file mode 100644 index 1a07228a..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfo.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d53d7d95f4c0101499c71adc21834733 -timeCreated: 1664198197 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfoProvider.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfoProvider.cs deleted file mode 100644 index ec8c0e84..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfoProvider.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; - -namespace Cdm.Authentication -{ - public interface IUserInfoProvider - { - /// - /// Obtains user information using third-party authentication service using data provided via callback request. - /// - /// Optional cancellation token. - Task GetUserInfoAsync(CancellationToken cancellationToken = default); - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfoProvider.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfoProvider.cs.meta deleted file mode 100644 index 0ec487b3..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/IUserInfoProvider.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: ba989f3b48d61f9499d8451db8237a7e -timeCreated: 1663698390 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking.meta deleted file mode 100644 index 63d8f2ea..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7e2694824dd4c6443a4b6875ae3196d9 -timeCreated: 1664830418 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServer.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServer.cs deleted file mode 100644 index 1862bd4f..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServer.cs +++ /dev/null @@ -1,321 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using System.Web; -using Cdm.Authentication.Clients; -using Cdm.Authentication.OAuth2; -using Cdm.Authentication.Utils; -using Newtonsoft.Json; -using UnityEngine; - -namespace Cdm.Authentication.Mocking -{ - public class MockServer : MonoBehaviour - { - private const string UsernameKey = "username"; - private const string LoginPath = "/oauth/login"; - - [SerializeField] - [Tooltip("Don't forget to add '/' to the end.")] - private string _serverUrl = "http://localhost:8001/"; - - public string serverUrl - { - get => _serverUrl; - set => _serverUrl = value; - } - - [Header("Authorization Code Response")] - [SerializeField] - private bool _authorizationCodeErrorEnabled; - - public bool authorizationCodeErrorEnabled - { - get => _authorizationCodeErrorEnabled; - set => _authorizationCodeErrorEnabled = value; - } - - [SerializeField] - private AuthorizationCodeRequestErrorCode _authorizationCodeError; - - public AuthorizationCodeRequestErrorCode authorizationCodeError - { - get => _authorizationCodeError; - set => _authorizationCodeError = value; - } - - [Space] - [SerializeField] - private List _accessTokenResponses = new List(); - - public IList accessTokenResponses => _accessTokenResponses; - - private const string LoginPage = - "" + - "" + - " " + - " Mock Auth Server" + - " " + - " " + - "
" + - " " + - "

" + - " " + - "
" + - " " + - ""; - - private HttpListener _httpListener; - private Task _listenTask; - private bool _runServer = false; - - private string _authorizationCode; - private AuthorizationCodeRequest _authorizationCodeRequest; - private MockServerAccessTokenResponse _accessTokenResponse; - - private void Start() - { - _httpListener = new HttpListener(); - _httpListener.Prefixes.Add(serverUrl); - _httpListener.Start(); - - _listenTask = HandleIncomingConnectionsAsync(); - Debug.Log($"[{nameof(MockServer)}] Listening for connections on '{serverUrl}'"); - } - - private void OnEnable() - { - _runServer = true; - } - - private void OnDisable() - { - _runServer = false; - } - - private void OnDestroy() - { - //_listenTask.GetAwaiter().GetResult(); - _httpListener?.Close(); - } - - private async Task HandleIncomingConnectionsAsync() - { - while (_runServer) - { - var ctx = await _httpListener.GetContextAsync(); - var request = ctx.Request; - var response = ctx.Response; - - Debug.Log($"[{nameof(MockServer)}] [{request.HttpMethod}] {request.Url.AbsolutePath}"); - - if (request.HttpMethod == "GET" && request.Url.AbsolutePath == MockServerAuth.AuthorizationPath) - { - await HandleAuthorizationRequest(request, response); - } - else if (request.HttpMethod == "POST" && request.Url.AbsolutePath == LoginPath) - { - await HandleLoginRequest(request, response); - } - else if (request.HttpMethod == "POST" && request.Url.AbsolutePath == MockServerAuth.TokenPath) - { - await HandleTokenRequest(request, response); - } - else if (request.HttpMethod == "GET" && request.Url.AbsolutePath == "/favicon.ico") - { - // Ignore. - } - else - { - Debug.LogError($"[{nameof(MockServer)}] Invalid request."); - } - } - } - - private async Task HandleAuthorizationRequest(HttpListenerRequest request, HttpListenerResponse response) - { - _authorizationCode = ""; - _authorizationCodeRequest = null; - _accessTokenResponse = null; - - var query = HttpUtility.ParseQueryString(request.Url.Query); - if (!JsonHelper.TryGetFromNameValueCollection( - query, out var authorizationRequest)) - { - Debug.LogError( - $"[{nameof(MockServer)}] No authorization code request data was sent with the query: '{request.Url.Query}'"); - return; - } - - _authorizationCodeRequest = authorizationRequest; - - if (authorizationCodeErrorEnabled) - { - var errorResponse = new AuthorizationCodeRequestError() - { - code = authorizationCodeError, - state = authorizationRequest.state - }; - - var responseQuery = JsonHelper.ToDictionary(errorResponse); - var responseUrl = UrlBuilder.New(authorizationRequest.redirectUri) - .SetQueryParameters(responseQuery).ToString(); - - response.Redirect(responseUrl); - response.Close(); - } - else - { - var data = Encoding.UTF8.GetBytes(LoginPage); - response.ContentType = "text/html"; - response.ContentEncoding = Encoding.UTF8; - response.ContentLength64 = data.LongLength; - - await response.OutputStream.WriteAsync(data, 0, data.Length); - response.Close(); - } - } - - private async Task HandleLoginRequest(HttpListenerRequest request, HttpListenerResponse response) - { - if (!request.HasEntityBody) - { - Debug.LogError($"[{nameof(MockServer)}] No body data was sent with the request."); - return; - } - - using var reader = new StreamReader(request.InputStream, request.ContentEncoding); - var content = await reader.ReadToEndAsync(); - var query = HttpUtility.ParseQueryString(content); - - Dictionary responseQuery; - - var username = query[UsernameKey]; - _accessTokenResponse = _accessTokenResponses.FirstOrDefault(x => x.username == username); - if (_accessTokenResponse != null) - { - _authorizationCode = Guid.NewGuid().ToString("D"); - - var authorizationResponse = new AuthorizationCodeResponse() - { - code = _authorizationCode, - state = _authorizationCodeRequest.state - }; - - responseQuery = JsonHelper.ToDictionary(authorizationResponse); - } - else - { - Debug.Log($"[{nameof(MockServer)}] User could not found: '{username}'"); - - var errorResponse = new AuthorizationCodeRequestError() - { - code = AuthorizationCodeRequestErrorCode.ServerError, - state = _authorizationCodeRequest.state - }; - - responseQuery = JsonHelper.ToDictionary(errorResponse); - } - - var responseUrl = UrlBuilder.New(_authorizationCodeRequest.redirectUri) - .SetQueryParameters(responseQuery).ToString(); - - response.Redirect(responseUrl); - response.Close(); - } - - private async Task HandleTokenRequest(HttpListenerRequest request, HttpListenerResponse response) - { - if (!request.HasEntityBody) - { - Debug.LogError($"[{nameof(MockServer)}] No body data was sent with the request."); - return; - } - - using var reader = new StreamReader(request.InputStream, request.ContentEncoding); - var content = await reader.ReadToEndAsync(); - var query = HttpUtility.ParseQueryString(content); - - string responseContent; - HttpStatusCode responseStatus; - - if (JsonHelper.TryGetFromNameValueCollection(query, out var accessTokenRequest)) - { - if (_accessTokenResponse.accessTokenErrorEnabled) - { - var tokenResponse = new AccessTokenRequestError() - { - code = _accessTokenResponse.accessTokenError - }; - - responseStatus = HttpStatusCode.BadRequest; - responseContent = JsonConvert.SerializeObject(tokenResponse); - } - else - { - var tokenResponse = new AccessTokenResponse() - { - accessToken = Guid.NewGuid().ToString("D"), - expiresIn = 3600, - refreshToken = Guid.NewGuid().ToString("D"), - tokenType = "Bearer", - scope = _authorizationCodeRequest.scope - }; - responseStatus = HttpStatusCode.OK; - responseContent = JsonConvert.SerializeObject(tokenResponse); - } - } - else if (JsonHelper.TryGetFromNameValueCollection(query, out var refreshTokenRequest)) - { - if (_accessTokenResponse.accessTokenErrorOnRefreshEnabled) - { - var tokenResponse = new AccessTokenRequestError() - { - code = _accessTokenResponse.accessTokenErrorOnRefresh - }; - - responseStatus = HttpStatusCode.BadRequest; - responseContent = JsonConvert.SerializeObject(tokenResponse); - } - else - { - var tokenResponse = new AccessTokenResponse() - { - accessToken = Guid.NewGuid().ToString("D"), - expiresIn = 3600, - tokenType = "Bearer", - scope = _authorizationCodeRequest.scope - }; - - responseStatus = HttpStatusCode.OK; - responseContent = JsonConvert.SerializeObject(tokenResponse); - } - } - else - { - var error = new AccessTokenRequestError() - { - code = AccessTokenRequestErrorCode.UnsupportedGrantType, - description = - "Unsupported grant type. Supported grant types are: 'authorization_code' and 'refresh_token'" - }; - - responseStatus = HttpStatusCode.BadRequest; - responseContent = JsonConvert.SerializeObject(error); - } - - var data = Encoding.UTF8.GetBytes(responseContent); - response.ContentType = "application/json"; - response.ContentEncoding = Encoding.UTF8; - response.ContentLength64 = data.LongLength; - response.StatusCode = (int) responseStatus; - - await response.OutputStream.WriteAsync(data, 0, data.Length); - response.Close(); - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServer.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServer.cs.meta deleted file mode 100644 index 120a1e33..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServer.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9c6d0808b59c9fc4f8c7182ca780b751 -timeCreated: 1664371505 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServerAccessTokenResponse.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServerAccessTokenResponse.cs deleted file mode 100644 index 6a1feed1..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServerAccessTokenResponse.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using Cdm.Authentication.OAuth2; -using UnityEngine; - -namespace Cdm.Authentication.Mocking -{ - [Serializable] - public class MockServerAccessTokenResponse - { - public string username; - - [Header("Exchanging authorization code with access token phase.")] - public bool accessTokenErrorEnabled; - public AccessTokenRequestErrorCode accessTokenError; - - [Header("Refreshing access token with the refresh token phase.")] - public bool accessTokenErrorOnRefreshEnabled; - public AccessTokenRequestErrorCode accessTokenErrorOnRefresh; - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServerAccessTokenResponse.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServerAccessTokenResponse.cs.meta deleted file mode 100644 index a7794c20..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Mocking/MockServerAccessTokenResponse.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 123f19fd09f18dd41b9a274bfa729638 -timeCreated: 1664827609 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2.meta deleted file mode 100644 index 6cd87efc..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1c4afa3d57b5f2f4d9b3bb0d1feda832 -timeCreated: 1664212345 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequest.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequest.cs deleted file mode 100644 index 07c325ba..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequest.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Runtime.Serialization; -using UnityEngine.Scripting; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// OAuth 2.0 request for an access token using an authorization code as specified in - /// http://tools.ietf.org/html/rfc6749#section-4.1.3. - /// - [Preserve] - [DataContract] - public class AccessTokenRequest - { - /// - /// Gets the authorization grant type as 'authorization_code'. - /// - [Preserve] - [DataMember(IsRequired = true, Name = "grant_type")] - public string grantType => "authorization_code"; - - /// - /// Gets or sets the authorization code received from the authorization server. - /// - [Preserve] - [DataMember(IsRequired = true, Name = "code")] - public string code { get; set; } - - /// - /// Gets or sets the client identifier as described in https://www.rfc-editor.org/rfc/rfc6749#section-3.2.1. - /// - [Preserve] - [DataMember(IsRequired = true, Name = "client_id")] - public string clientId { get; set; } - - /// - /// Gets or sets the client secret. - /// - [Preserve] - [DataMember(Name = "client_secret")] - public string clientSecret { get; set; } - - /// - /// Gets or sets the redirect URI parameter matching the redirect URI parameter in the authorization request. - /// - [Preserve] - [DataMember(Name = "redirect_uri")] - public string redirectUri { get; set; } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequest.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequest.cs.meta deleted file mode 100644 index 4141ea7b..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequest.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 19b1ff8c6122dc944bbd25e57ce8f03b -timeCreated: 1663675827 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestError.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestError.cs deleted file mode 100644 index c3a578f4..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestError.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Runtime.Serialization; -using UnityEngine.Scripting; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// OAuth 2.0 model for a unsuccessful access token response as specified in - /// http://tools.ietf.org/html/rfc6749#section-5.2. - /// - [Preserve] - [DataContract] - public class AccessTokenRequestError - { - /// - /// Gets or sets the error code as specified in http://tools.ietf.org/html/rfc6749#section-5.2. - /// - [Preserve] - [DataMember(IsRequired = true, Name = "error")] - public AccessTokenRequestErrorCode code { get; set; } - - /// - /// Gets or sets a human-readable text which provides additional information used to assist the client - /// developer in understanding the error occurred. - /// - [Preserve] - [DataMember(Name = "error_description")] - public string description { get; set; } - - /// - /// Gets or sets the URI identifying a human-readable web page with provides information about the error. - /// - [Preserve] - [DataMember(Name = "error_uri")] - public string uri { get; set; } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestError.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestError.cs.meta deleted file mode 100644 index df136b00..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestError.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 31a4eb5c0eca90b4ebefe589faa6f610 -timeCreated: 1663694297 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestErrorCode.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestErrorCode.cs deleted file mode 100644 index 4bf8da61..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestErrorCode.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Runtime.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using UnityEngine.Scripting; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// The authorization server responds with an HTTP 400 (Bad Request) status code (unless specified otherwise) and - /// includes the following parameters with the response. - /// - [JsonConverter(typeof(StringEnumConverter))] - [DataContract] - [Preserve] - public enum AccessTokenRequestErrorCode - { - /// - /// The request is missing a required parameter, includes an unsupported parameter value - /// (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than - /// one mechanism for authenticating the client, or is otherwise malformed. - /// - [Preserve] - [EnumMember(Value = "invalid_request")] - InvalidRequest, - - /// - /// Client authentication failed (e.g., unknown client, no client authentication included, - /// or unsupported authentication method). The authorization server MAY return an HTTP 401 (Unauthorized) - /// status code to indicate which HTTP authentication schemes are supported. If the client attempted to - /// authenticate via the "Authorization" request header field, the authorization server MUST respond with - /// an HTTP 401 (Unauthorized) status code and include the "WWW-Authenticate" response header field matching - /// the authentication scheme used by the client. - /// - [Preserve] - [EnumMember(Value = "invalid_client")] - InvalidClient, - - /// - /// The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token - /// is invalid, expired, revoked, does not match the redirection URI used in the authorization request, - /// or was issued to another client. - /// - [Preserve] - [EnumMember(Value = "invalid_grant")] - InvalidGrant, - - /// - /// The authenticated client is not authorized to use this authorization grant type. - /// - [Preserve] - [EnumMember(Value = "unauthorized_client")] - UnauthorizedClient, - - /// - /// The authorization grant type is not supported by the authorization server. - /// - [Preserve] - [EnumMember(Value = "unsupported_grant_type")] - UnsupportedGrantType, - - /// - /// The requested scope is invalid, unknown, malformed, or exceeds the scope granted by the resource owner. - /// - [Preserve] - [EnumMember(Value = "invalid_scope")] - InvalidScope, - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestErrorCode.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestErrorCode.cs.meta deleted file mode 100644 index 456918d5..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestErrorCode.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 654089d53efe0e54aa1994be6b75750d -timeCreated: 1663681686 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestException.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestException.cs deleted file mode 100644 index b87614d6..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestException.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Net; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// Access token response exception which is thrown in case of receiving a token error when an authorization code - /// or an access token is expected. - /// - public class AccessTokenRequestException : Exception - { - /// - /// HTTP status code of error, or null if unknown. - /// - public HttpStatusCode? statusCode { get; } - - /// - /// The error information. - /// - public AccessTokenRequestError error { get; } - - public AccessTokenRequestException(AccessTokenRequestError error, HttpStatusCode? statusCode) - : base(error.description) - { - this.error = error; - this.statusCode = statusCode; - } - - public AccessTokenRequestException(AccessTokenRequestError error, HttpStatusCode? statusCode, string message) - : base(message) - { - this.error = error; - this.statusCode = statusCode; - } - - public AccessTokenRequestException(AccessTokenRequestError error, HttpStatusCode? statusCode, - string message, Exception innerException) : base(message, innerException) - { - this.error = error; - this.statusCode = statusCode; - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestException.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestException.cs.meta deleted file mode 100644 index 01fd37e6..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenRequestException.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a103fb9088c8f2e4992237c40770ab24 -timeCreated: 1663721719 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponse.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponse.cs deleted file mode 100644 index 3595603f..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponse.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Net.Http.Headers; -using System.Runtime.Serialization; -using UnityEngine.Scripting; - -namespace Cdm.Authentication.OAuth2 -{ - [Preserve] - [DataContract] - public class AccessTokenResponse - { - /// - /// Gets or sets the access token issued by the authorization server. - /// - [Preserve] - [DataMember(IsRequired = true, Name = "access_token")] - public string accessToken { get; set; } - - /// - /// Gets or sets the refresh token which can be used to obtain a new access token. - /// - [Preserve] - [DataMember(Name = "refresh_token")] - public string refreshToken { get; set; } - - /// - /// Gets or sets the token type as specified in http://tools.ietf.org/html/rfc6749#section-7.1. - /// - [Preserve] - [DataMember(IsRequired = true, Name = "token_type")] - public string tokenType { get; set; } - - /// - /// Gets or sets the lifetime in seconds of the access token. - /// - [Preserve] - [DataMember(Name = "expires_in")] - public long? expiresIn { get; set; } - - /// - /// Gets or sets the scope of the access token as specified in http://tools.ietf.org/html/rfc6749#section-3.3. - /// - [Preserve] - [DataMember(Name = "scope")] - public string scope { get; set; } - - /// - /// The date and time that this token was issued, expressed in UTC. - /// - /// - /// This should be set by the client after the token was received from the server. - /// - public DateTime? issuedAt { get; set; } - - /// - /// Seconds till the expires returned by provider. - /// - public DateTime? expiresAt - { - get - { - if (issuedAt.HasValue && expiresIn.HasValue) - { - return issuedAt.Value + TimeSpan.FromSeconds(expiresIn.Value); - } - - return null; - } - } - - public AuthenticationHeaderValue GetAuthenticationHeader() - { - return new AuthenticationHeaderValue(tokenType, accessToken); - } - - /// - /// Returns true if the token is expired or it's going to expire soon. - /// - /// - /// If a token response does not have then it's considered expired. - /// If is null, the token is also considered expired. - /// - public bool IsExpired() - { - return string.IsNullOrEmpty(accessToken) || expiresAt == null || expiresAt < DateTime.UtcNow; - } - - /// - /// Returns true if the refresh token is exist. - /// - public bool HasRefreshToken() - { - return !string.IsNullOrEmpty(refreshToken); - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponse.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponse.cs.meta deleted file mode 100644 index e401fd52..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponse.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d6d9a14315958944e88ae85941355d1f -timeCreated: 1663675856 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponseExtensions.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponseExtensions.cs deleted file mode 100644 index 7972f752..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponseExtensions.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace Cdm.Authentication.OAuth2 -{ - public static class AccessTokenResponseExtensions - { - public static bool IsNullOrExpired(this AccessTokenResponse accessTokenResponse) - { - return accessTokenResponse == null || accessTokenResponse.IsExpired(); - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponseExtensions.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponseExtensions.cs.meta deleted file mode 100644 index d339e117..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AccessTokenResponseExtensions.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: fb41bc26edd47c84ca1a29a4d879f22b -timeCreated: 1664201294 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationError.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationError.cs deleted file mode 100644 index 431e8989..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationError.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Cdm.Authentication.OAuth2 -{ - public enum AuthenticationError - { - Other = 0, - Cancelled = 1, - Timeout = 2 - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationError.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationError.cs.meta deleted file mode 100644 index 8edf341e..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationError.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: cfd6739d6f1e2af43b1e95a761319db8 -timeCreated: 1664187833 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationException.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationException.cs deleted file mode 100644 index 5f08450e..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationException.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace Cdm.Authentication.OAuth2 -{ - public class AuthenticationException : Exception - { - public AuthenticationError error { get; } - - public AuthenticationException(AuthenticationError error) - { - this.error = error; - } - - public AuthenticationException(AuthenticationError error, string message) : base(message) - { - this.error = error; - } - - public AuthenticationException(AuthenticationError error, string message, Exception innerException) - : base(message, innerException) - { - this.error = error; - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationException.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationException.cs.meta deleted file mode 100644 index fd966be8..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationException.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: c9e95a9cecb26bb4d8f0e7b962a529cb -timeCreated: 1664187781 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationSession.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationSession.cs deleted file mode 100644 index 7a472d84..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationSession.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Net.Http.Headers; -using System.Threading; -using System.Threading.Tasks; -using Cdm.Authentication.Browser; -using UnityEngine; - -namespace Cdm.Authentication.OAuth2 -{ - public class AuthenticationSession : IDisposable - { - private readonly AuthorizationCodeFlow _client; - private readonly IBrowser _browser; - - public TimeSpan loginTimeout { get; set; } = TimeSpan.FromMinutes(10); - - public AuthenticationSession(AuthorizationCodeFlow client, IBrowser browser) - { - _client = client; - _browser = browser; - } - - public bool ShouldAuthenticate() - { - return _client.ShouldRequestAuthorizationCode(); - } - - public bool SupportsUserInfo() - { - return _client is IUserInfoProvider; - } - - public async Task GetAuthenticationHeaderAsync() - { - var tokenResponse = await _client.GetOrRefreshTokenAsync(); - return tokenResponse.GetAuthenticationHeader(); - } - - /// - /// Asynchronously authorizes the installed application to access user's protected data. - /// - /// Cancellation token to cancel operation. - /// - /// - /// - public async Task AuthenticateAsync(CancellationToken cancellationToken = default) - { - using var timeoutCancellationTokenSource = new CancellationTokenSource(loginTimeout); - - try - { - // 1. Create authorization request URL. - Debug.Log("Making authorization request..."); - - var redirectUrl = _client.configuration.redirectUri; - var authorizationUrl = _client.GetAuthorizationUrl(); - - // 2. Get authorization code grant using login form in the browser. - Debug.Log("Getting authorization grant using browser login..."); - - using var loginCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCancellationTokenSource.Token); - - var browserResult = await _browser.StartAsync(authorizationUrl, redirectUrl, loginCancellationTokenSource.Token); - if (browserResult.status == BrowserStatus.Success) - { - // 3. Exchange authorization code for access and refresh tokens. - Debug.Log("Exchanging authorization code for access and refresh tokens..."); - -#if UNITY_EDITOR - Debug.Log($"Redirect URL: {browserResult.redirectUrl}"); -#endif - return await _client.ExchangeCodeForAccessTokenAsync(browserResult.redirectUrl, cancellationToken); - } - - if (browserResult.status == BrowserStatus.UserCanceled) - { - throw new AuthenticationException(AuthenticationError.Cancelled, browserResult.error); - } - - throw new AuthenticationException(AuthenticationError.Other, browserResult.error); - } - catch (TaskCanceledException e) - { - if (timeoutCancellationTokenSource.IsCancellationRequested) - throw new AuthenticationException(AuthenticationError.Timeout, "Operation timed out."); - - throw new AuthenticationException(AuthenticationError.Cancelled, "Operation was cancelled.", e); - } - } - - /// - public async Task GetOrRefreshTokenAsync(CancellationToken cancellationToken = default) - { - return await _client.GetOrRefreshTokenAsync(cancellationToken); - } - - /// - public async Task RefreshTokenAsync(CancellationToken cancellationToken = default) - { - return await _client.RefreshTokenAsync(cancellationToken); - } - - /// - public async Task RefreshTokenAsync(string refreshToken, CancellationToken cancellationToken = default) - { - return await _client.RefreshTokenAsync(refreshToken, cancellationToken); - } - - /// - /// Gets the user info if authentication client supports getting user info. - /// - /// Cancellation token to cancel operation. - /// The user info if exist; otherwise returns null. - /// - public async Task GetUserInfoAsync(CancellationToken cancellationToken = default) - { - if (SupportsUserInfo()) - { - return await ((IUserInfoProvider)_client).GetUserInfoAsync(cancellationToken); - } - - return null; - } - - public void Dispose() - { - _client?.Dispose(); - } - } -} diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationSession.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationSession.cs.meta deleted file mode 100644 index a941c3a7..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthenticationSession.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0af43541c044c2341876827e95dd01b8 -timeCreated: 1664187130 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlow.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlow.cs deleted file mode 100644 index 6a5d3ac9..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlow.cs +++ /dev/null @@ -1,317 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Runtime.Serialization; -using System.Security; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using System.Web; -using Cdm.Authentication.Utils; -using Newtonsoft.Json; -using UnityEngine; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// Supports 'Authorization Code' flow. Enables user sign-in and access to web APIs on behalf of the user. - /// - /// The OAuth 2.0 authorization code grant type, enables a client application to obtain - /// authorized access to protected resources like web APIs. The auth code flow requires a user-agent that supports - /// redirection from the authorization server back to your application. For example, a web browser, desktop, - /// or mobile application operated by a user to sign in to your app and access their data. - /// - public abstract class AuthorizationCodeFlow : IDisposable - { - /// - /// The endpoint for authorization server. This is used to get the authorization code. - /// - public abstract string authorizationUrl { get; } - - /// - /// The endpoint for authentication server. This is used to exchange the authorization code for an access token. - /// - public abstract string accessTokenUrl { get; } - - /// - /// The state; any additional information that was provided by application and is posted back by service. - /// - /// - public string state { get; private set; } - - /// - /// Gets the client configuration for the authentication method. - /// - public Configuration configuration { get; } - - protected AccessTokenResponse accessTokenResponse { get; private set; } - protected HttpClient httpClient { get; } - - protected AuthorizationCodeFlow(Configuration configuration) - { - this.configuration = configuration; - - httpClient = new HttpClient(); - httpClient.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue() { NoCache = true, NoStore = true }; - } - - /// - /// Determines the need for retrieval of a new authorization code. - /// - /// Indicates if a new authorization code needs to be retrieved. - public bool ShouldRequestAuthorizationCode() - { - return accessTokenResponse == null || !accessTokenResponse.HasRefreshToken(); - } - - /// - /// Determines the need for retrieval of a new access token using the refresh token. - /// - /// - /// If does not exist, then get new authorization code first. - /// - /// Indicates if a new access token needs to be retrieved. - /// - public bool ShouldRefreshToken() - { - return accessTokenResponse.IsNullOrExpired(); - } - - /// , - /// Gets an authorization code request URI with the specified . - /// - /// The authorization code request URI. - public string GetAuthorizationUrl() - { - // Generate new state. - state = Guid.NewGuid().ToString("D"); - - var parameters = GetAuthorizationUrlParameters(); - - return UrlBuilder.New(authorizationUrl).SetQueryParameters(parameters).ToString(); - } - - protected virtual Dictionary GetAuthorizationUrlParameters() - { - return JsonHelper.ToDictionary( - new AuthorizationCodeRequest() - { - clientId = configuration.clientId, - redirectUri = configuration.redirectUri, - scope = configuration.scope, - state = state - } - ); - } - - /// - /// Asynchronously exchanges code with a token. - /// - /// - /// Redirect URL which is retrieved - /// from the browser result. - /// - /// Cancellation token to cancel operation. - /// Access token response which contains the access token. - /// - /// - /// - /// - public virtual async Task ExchangeCodeForAccessTokenAsync(string redirectUrl, CancellationToken cancellationToken = default) - { - var authorizationResponseUri = new Uri(redirectUrl); - var query = HttpUtility.ParseQueryString(authorizationResponseUri.Query); - - // Is there any error? - if (JsonHelper.TryGetFromNameValueCollection(query, out var authorizationError)) - throw new AuthorizationCodeRequestException(authorizationError); - - if (!JsonHelper.TryGetFromNameValueCollection(query, out var authorizationResponse)) - throw new Exception("Authorization code could not get."); - - // Validate authorization response state. - if (!string.IsNullOrEmpty(state) && state != authorizationResponse.state) - throw new SecurityException($"Invalid state got: {authorizationResponse.state}"); - - var parameters = GetAccessTokenParameters(authorizationResponse.code); - - Debug.Assert(parameters != null); - - accessTokenResponse = await GetAccessTokenInternalAsync(new FormUrlEncodedContent(parameters), cancellationToken); - return accessTokenResponse; - } - - protected virtual Dictionary GetAccessTokenParameters(string code) - { - return JsonHelper.ToDictionary( - new AccessTokenRequest() - { - code = code, - clientId = configuration.clientId, - clientSecret = configuration.clientSecret, - redirectUri = configuration.redirectUri - } - ); - } - - /// - /// Gets the access token immediately from cache if is false; - /// or refreshes and returns it using the refresh token. - /// if available. - /// - /// Cancellation token to cancel operation. - /// If access token cannot be granted. - public async Task GetOrRefreshTokenAsync(CancellationToken cancellationToken = default) - { - if (ShouldRefreshToken()) - { - return await RefreshTokenAsync(cancellationToken); - } - - // Return from the cache immediately. - return accessTokenResponse; - } - - /// - /// Asynchronously refreshes an access token using the refresh token from the . - /// - /// Cancellation token to cancel operation. - /// Token response which contains the access token and the refresh token. - public async Task RefreshTokenAsync(CancellationToken cancellationToken = default) - { - if (accessTokenResponse == null) - throw new AccessTokenRequestException(new AccessTokenRequestError() { code = AccessTokenRequestErrorCode.InvalidGrant, description = "Authentication required." }, null); - - return await RefreshTokenAsync(accessTokenResponse.refreshToken, cancellationToken); - } - - /// - /// Asynchronously refreshes an access token using a refresh token. - /// - /// Refresh token which is used to get a new access token. - /// Cancellation token to cancel operation. - /// Token response which contains the access token and the input refresh token. - public async Task RefreshTokenAsync(string refreshToken, CancellationToken cancellationToken = default) - { - if (string.IsNullOrEmpty(refreshToken)) - { - var error = new AccessTokenRequestError() { code = AccessTokenRequestErrorCode.InvalidGrant, description = "Refresh token does not exist." }; - - throw new AccessTokenRequestException(error, null); - } - - var parameters = JsonHelper.ToDictionary(new RefreshTokenRequest() { refreshToken = refreshToken, scope = configuration.scope }); - - Debug.Assert(parameters != null); - - var tokenResponse = await GetAccessTokenInternalAsync(new FormUrlEncodedContent(parameters), cancellationToken); - if (!tokenResponse.HasRefreshToken()) - { - tokenResponse.refreshToken = refreshToken; - } - - accessTokenResponse = tokenResponse; - return accessTokenResponse; - } - - private async Task GetAccessTokenInternalAsync(FormUrlEncodedContent content, CancellationToken cancellationToken = default) - { - Debug.Assert(content != null); - - var authString = $"{configuration.clientId}:{configuration.clientSecret}"; - var base64AuthString = Convert.ToBase64String(Encoding.UTF8.GetBytes(authString)); - - var tokenRequest = new HttpRequestMessage(HttpMethod.Post, accessTokenUrl); - tokenRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - tokenRequest.Headers.Authorization = new AuthenticationHeaderValue("Basic", base64AuthString); - tokenRequest.Content = content; - -#if UNITY_EDITOR - Debug.Log($"{tokenRequest}"); - Debug.Log($"{await tokenRequest.Content.ReadAsStringAsync()}"); -#endif - - var response = await httpClient.SendAsync(tokenRequest, cancellationToken); - if (response.IsSuccessStatusCode) - { - var responseJson = await response.Content.ReadAsStringAsync(); - -#if UNITY_EDITOR - Debug.Log(responseJson); -#endif - - var tokenResponse = JsonConvert.DeserializeObject(responseJson); - tokenResponse.issuedAt = DateTime.UtcNow; - return tokenResponse; - } - - AccessTokenRequestError error = null; - try - { - var errorJson = await response.Content.ReadAsStringAsync(); - error = JsonConvert.DeserializeObject(errorJson); - } - catch (Exception) - { - // ignored - } - - throw new AccessTokenRequestException(error, response.StatusCode); - } - - public void Dispose() - { - httpClient?.Dispose(); - } - - /// - /// The configuration of third-party authentication service client. - /// - [DataContract] - public struct Configuration - { - /// - /// The client identifier issued to the client during the registration process described by - /// Section 2.2. - /// - [DataMember(Name = "client_id", IsRequired = true)] - public string clientId { get; set; } - - /// - /// The client secret. The client MAY omit the parameter if the client secret is an empty string. - /// - [DataMember(Name = "client_secret")] - public string clientSecret { get; set; } - - /// - /// The authorization and token endpoints allow the client to specify the scope of the access request using - /// the "scope" request parameter. In turn, the authorization server uses the "scope" response parameter to - /// inform the client of the scope of the access token issued. The value of the scope parameter is expressed - /// as a list of space- delimited, case-sensitive strings. The strings are defined by the authorization server. - /// If the value contains multiple space-delimited strings, their order does not matter, and each string adds an - /// additional access range to the requested scope. - /// - [DataMember(Name = "scope")] - public string scope { get; set; } - - /// - /// After completing its interaction with the resource owner, the authorization server directs the resource - /// owner's user-agent back to the client. The authorization server redirects the user-agent to the client's - /// redirection endpoint previously established with the authorization server during the client registration - /// process or when making the authorization request. - /// - /// - /// The redirection endpoint URI MUST be an absolute URI as defined by - /// [RFC3986] Section 4.3. - /// The endpoint URI MAY include an "application/x-www-form-urlencoded" formatted (per - /// Appendix B) query - /// component ([RFC3986] Section 3.4), - /// which MUST be retained when adding additional query parameters. The endpoint URI MUST NOT include - /// a fragment component. - /// - [DataMember(Name = "redirect_uri")] - public string redirectUri { get; set; } - } - } -} diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlow.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlow.cs.meta deleted file mode 100644 index ed268459..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlow.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: f98046089ecd0ae4eaee25633242d66e -timeCreated: 1663698298 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlowWithPkce.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlowWithPkce.cs deleted file mode 100644 index c11c8660..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlowWithPkce.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Security.Cryptography; -using System.Text; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// OAuth 2.0 'Authorization Code' flow with PKCE (Proof Key for Code Exchange). - /// - /// PKCE (RFC 7636) is an extension to the Authorization Code flow to prevent CSRF and authorization code injection - /// attacks. PKCE is not a form of client authentication, and PKCE is not a replacement for a client secret or - /// other client authentication. PKCE is recommended even if a client is using a client secret or other form - /// of client authentication like private_key_jwt. - /// - /// https://www.rfc-editor.org/rfc/rfc7636 - /// - public abstract class AuthorizationCodeFlowWithPkce : AuthorizationCodeFlow - { - private string _codeVerifier; - - protected AuthorizationCodeFlowWithPkce(Configuration configuration) - : base(configuration) { } - - protected override Dictionary GetAuthorizationUrlParameters() - { - var parameters = base.GetAuthorizationUrlParameters(); - - _codeVerifier = GenerateRandomDataBase64url(32); - var codeChallenge = Base64UrlEncodeNoPadding(Sha256Ascii(_codeVerifier)); - - parameters.Add("code_challenge", codeChallenge); - parameters.Add("code_challenge_method", "S256"); - - return parameters; - } - - protected override Dictionary GetAccessTokenParameters(string code) - { - var parameters = base.GetAccessTokenParameters(code); - parameters.Add("code_verifier", _codeVerifier); - return parameters; - } - - private static string GenerateRandomDataBase64url(uint length) - { - var rng = new RNGCryptoServiceProvider(); - var bytes = new byte[length]; - rng.GetBytes(bytes); - return Base64UrlEncodeNoPadding(bytes); - } - - /// - /// Base64url no-padding encodes the given input buffer. - /// - /// - /// - private static string Base64UrlEncodeNoPadding(byte[] buffer) - { - var base64 = Convert.ToBase64String(buffer); - - // Converts base64 to base64url. - base64 = base64.Replace("+", "-"); - base64 = base64.Replace("/", "_"); - // Strips padding. - base64 = base64.Replace("=", ""); - - return base64; - } - - /// - /// Returns the SHA256 hash of the input string, which is assumed to be ASCII. - /// - private static byte[] Sha256Ascii(string text) - { - var bytes = Encoding.ASCII.GetBytes(text); - using (SHA256Managed sha256 = new SHA256Managed()) - { - return sha256.ComputeHash(bytes); - } - } - } -} diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlowWithPkce.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlowWithPkce.cs.meta deleted file mode 100644 index 468f74be..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeFlowWithPkce.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fe1a70dac58210c4284abf52f2e7ebd7 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequest.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequest.cs deleted file mode 100644 index e426863f..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequest.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Runtime.Serialization; -using UnityEngine.Scripting; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// OAuth 2.0 request for an access token using an authorization code as specified in - /// http://tools.ietf.org/html/rfc6749#section-4.1.1. - /// - [Preserve] - [DataContract] - public class AuthorizationCodeRequest - { - /// - /// Gets the response type which is the 'code'. - /// - [Preserve] - [DataMember(Name = "response_type", IsRequired = true)] - public string responseType => "code"; - - /// - /// Gets or sets the client identifier as specified in https://www.rfc-editor.org/rfc/rfc6749#section-2.2. - /// - [Preserve] - [DataMember(Name = "client_id", IsRequired = true)] - public string clientId { get; set; } - - /// - /// Gets or sets the URI that the authorization server directs the resource owner's user-agent back to the - /// client after a successful authorization grant, as specified in - /// http://tools.ietf.org/html/rfc6749#section-3.1.2 or null for none. - /// - [Preserve] - [DataMember(Name = "redirect_uri")] - public string redirectUri { get; set; } - - /// - /// Gets or sets space-separated list of scopes, as specified in - /// http://tools.ietf.org/html/rfc6749#section-3.3 or null for none. - /// - [Preserve] - [DataMember(Name = "scope")] - public string scope { get; set; } - - /// - /// Gets or sets the state (an opaque value used by the client to maintain state between the request and - /// callback, as mentioned in http://tools.ietf.org/html/rfc6749#section-3.1.2.2 or null for none. - /// - [Preserve] - [DataMember(Name = "state")] - public string state { get; set; } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequest.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequest.cs.meta deleted file mode 100644 index 5f5c1042..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequest.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d5c316f8b12fd6a4090d7a1681053bc4 -timeCreated: 1663697096 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestError.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestError.cs deleted file mode 100644 index 18936f59..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestError.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Runtime.Serialization; -using UnityEngine.Scripting; - -namespace Cdm.Authentication.OAuth2 -{ - [Preserve] - [DataContract] - public class AuthorizationCodeRequestError - { - [Preserve] - [DataMember(IsRequired = true, Name = "error")] - public AuthorizationCodeRequestErrorCode code { get; set; } - - /// - /// OPTIONAL. Human-readable ASCII [USASCII] - /// text providing additional information, used to assist the client developer in understanding - /// the error that occurred. - /// - [Preserve] - [DataMember(Name = "error_description")] - public string description { get; set; } - - /// - /// OPTIONAL. A URI identifying a human-readable web page with information about the error, used to provide - /// the client developer with additional information about the error. - /// - [Preserve] - [DataMember(Name = "error_uri")] - public string uri { get; set; } - - /// - /// REQUIRED if a "state" parameter was present in the client authorization request. The exact value received - /// from the client. - /// - [Preserve] - [DataMember(Name = "state")] - public string state { get; set; } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestError.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestError.cs.meta deleted file mode 100644 index a13f4416..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestError.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0eb20234c1e0836448be534ea5062cef -timeCreated: 1663724095 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestErrorCode.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestErrorCode.cs deleted file mode 100644 index 237a27e0..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestErrorCode.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.Runtime.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using UnityEngine.Scripting; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// - /// - [Preserve] - [JsonConverter(typeof(StringEnumConverter))] - [DataContract] - public enum AuthorizationCodeRequestErrorCode - { - /// - /// The request is missing a required parameter, includes an invalid parameter value, includes a parameter - /// more than once, or is otherwise malformed. - /// - [Preserve] - [EnumMember(Value = "invalid_request")] - InvalidRequest, - - /// - /// The client is not authorized to request an authorization code using this method. - /// - [Preserve] - [EnumMember(Value = "unauthorized_client")] - UnauthorizedClient, - - /// - /// The resource owner or authorization server denied the request. - /// - [Preserve] - [EnumMember(Value = "access_denied")] - AccessDenied, - - /// - /// The authorization server does not support obtaining an authorization code using this method. - /// - [Preserve] - [EnumMember(Value = "unsupported_response_type")] - UnsupportedResponseType, - - /// - /// The requested scope is invalid, unknown, or malformed. - /// - [Preserve] - [EnumMember(Value = "invalid_scope")] - InvalidScope, - - /// - /// The authorization server encountered an unexpected condition that prevented it from fulfilling the request. - /// (This error code is needed because a 500 Internal Server Error HTTP status code cannot be returned to - /// the client via an HTTP redirect.) - /// - [Preserve] - [EnumMember(Value = "server_error")] - ServerError, - - /// - /// The authorization server is currently unable to handle the request due to a temporary overloading or - /// maintenance of the server. (This error code is needed because a 503 Service Unavailable HTTP status code - /// cannot be returned to the client via an HTTP redirect.) - /// - [Preserve] - [EnumMember(Value = "temporarily_unavailable")] - TemporarilyUnavailable - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestErrorCode.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestErrorCode.cs.meta deleted file mode 100644 index 70c90aa6..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestErrorCode.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 78e9424b811b73643b1983afd500459e -timeCreated: 1663675095 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestException.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestException.cs deleted file mode 100644 index 1d554645..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestException.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; - -namespace Cdm.Authentication.OAuth2 -{ - public class AuthorizationCodeRequestException : Exception - { - public AuthorizationCodeRequestError error { get; } - - public AuthorizationCodeRequestException(AuthorizationCodeRequestError error) - { - this.error = error; - } - - public AuthorizationCodeRequestException(AuthorizationCodeRequestError error, string message) : base(message) - { - this.error = error; - } - - public AuthorizationCodeRequestException(AuthorizationCodeRequestError error, string message, Exception innerException) - : base(message, innerException) - { - this.error = error; - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestException.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestException.cs.meta deleted file mode 100644 index 6613c125..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeRequestException.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 2f3d870466f4d1442b24a9ba786bcbcd -timeCreated: 1663724223 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeResponse.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeResponse.cs deleted file mode 100644 index 1ecd73d4..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeResponse.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Runtime.Serialization; -using UnityEngine.Scripting; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// If the resource owner grants the access request, the authorization server issues an authorization code and - /// delivers it to the client by adding the following parameters to the query component of the redirection URI - /// using the "application/x-www-form-urlencoded" format, - /// per Appendix B. - /// - [Preserve] - [DataContract] - public class AuthorizationCodeResponse - { - /// - /// Gets or sets the authorization code received from the authorization server. - /// - [Preserve] - [DataMember(IsRequired = true, Name = "code")] - public string code { get; set; } - - /// - /// The exact value received from the client while making the authorization request as specified in - /// . - /// - [Preserve] - [DataMember(Name = "state")] - public string state { get; set; } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeResponse.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeResponse.cs.meta deleted file mode 100644 index a1cb7da5..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/AuthorizationCodeResponse.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 02496e162a88ed34ba3cc2595dc5add7 -timeCreated: 1663673077 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/RefreshTokenRequest.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/RefreshTokenRequest.cs deleted file mode 100644 index 230a30d8..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/RefreshTokenRequest.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Runtime.Serialization; -using UnityEngine.Scripting; - -namespace Cdm.Authentication.OAuth2 -{ - /// - /// OAuth 2.0 request to refresh an access token using a refresh token as specified in - /// http://tools.ietf.org/html/rfc6749#section-6. - /// - [Preserve] - [DataContract] - public class RefreshTokenRequest - { - /// - /// The grant type as 'refresh_token'. - /// - [Preserve] - [DataMember(IsRequired = true, Name = "grant_type")] - public string grantType => "refresh_token"; - - /// - /// REQUIRED. The refresh token issued to the client. - /// - [Preserve] - [DataMember(IsRequired = true, Name = "refresh_token")] - public string refreshToken { get; set; } - - /// - /// OPTIONAL. The scope of the access request as described by Section 3.3. The requested scope MUST NOT - /// include any scope not originally granted by the resource owner, and if omitted is treated as equal to - /// the scope originally granted by the resource owner. - /// - [Preserve] - [DataMember(Name = "scope")] - public string scope { get; set; } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/RefreshTokenRequest.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/RefreshTokenRequest.cs.meta deleted file mode 100644 index 6fd875f9..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/OAuth2/RefreshTokenRequest.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: dce64c3479ad97444a85e2d07c50bb80 -timeCreated: 1663696510 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils.meta deleted file mode 100644 index b051d0e6..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 4eec74a1c08560545b6efdb26dc0e629 -timeCreated: 1663799236 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/JsonHelper.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/JsonHelper.cs deleted file mode 100644 index e7c5ef33..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/JsonHelper.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace Cdm.Authentication.Utils -{ - public static class JsonHelper - { - public static Dictionary ToDictionary(object obj) - { - var dictionary = JObject.FromObject(obj).ToObject>(); - - if (dictionary != null) - { - // Remove empty parameters. - var keys = dictionary.Keys.Where(key => string.IsNullOrEmpty(dictionary[key])).ToArray(); - foreach (var key in keys) - { - dictionary.Remove(key); - } - } - - return dictionary; - } - - public static T FromDictionary(Dictionary dictionary) - { - return JObject.FromObject(dictionary).ToObject(); - } - - public static bool TryGetFromDictionary(Dictionary dictionary, out T value) - { - try - { - value = FromDictionary(dictionary); - return true; - } - catch (JsonSerializationException) - { - // ignored - } - - value = default; - return false; - } - - public static bool TryGetFromNameValueCollection(NameValueCollection collection, out T value) - { - var dictionary = new Dictionary(); - - foreach (string s in collection) - { - dictionary.Add(s, collection[s]); - } - - return TryGetFromDictionary(dictionary, out value); - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/JsonHelper.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/JsonHelper.cs.meta deleted file mode 100644 index 91a11038..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/JsonHelper.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: dc7a31a4c521e1a47bd5fd59649a3674 -timeCreated: 1663800310 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UrlBuilder.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UrlBuilder.cs deleted file mode 100644 index 285bbf4a..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UrlBuilder.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Web; - -namespace Cdm.Authentication.Utils -{ - public class UrlBuilder - { - private readonly UriBuilder _uriBuilder; - private readonly NameValueCollection _query; - - private UrlBuilder(string url) - { - _uriBuilder = new UriBuilder(url); - _query = HttpUtility.ParseQueryString(""); - } - - public static UrlBuilder New(string url) - { - return new UrlBuilder(url); - } - - public UrlBuilder SetQueryParameters(Dictionary parameters) - { - foreach (var p in parameters) - { - _query.Set(p.Key, p.Value); - } - - return this; - } - - public override string ToString() - { - _uriBuilder.Query = _query.ToString(); - return _uriBuilder.Uri.ToString(); - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UrlBuilder.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UrlBuilder.cs.meta deleted file mode 100644 index 4d6337ff..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UrlBuilder.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7053983744fd70f418b7bc0b26fbc52e -timeCreated: 1663715763 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UserInfoParser.cs b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UserInfoParser.cs deleted file mode 100644 index 98b2cbaa..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UserInfoParser.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading; -using System.Threading.Tasks; -using Newtonsoft.Json; -using UnityEngine; - -namespace Cdm.Authentication.Utils -{ - public static class UserInfoParser - { - public static async Task GetUserInfoAsync(HttpClient httpClient, string url, - AuthenticationHeaderValue authenticationHeader, CancellationToken cancellationToken = default) - where T : IUserInfo - { - var request = new HttpRequestMessage(HttpMethod.Get, url); - request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - request.Headers.Authorization = authenticationHeader; - -#if UNITY_EDITOR - Debug.Log($"{request}"); -#endif - - var response = await httpClient.SendAsync(request, cancellationToken); - if (response.IsSuccessStatusCode) - { - var content = await response.Content.ReadAsStringAsync(); - var userInfo = JsonConvert.DeserializeObject(content); - -#if UNITY_EDITOR - Debug.Log(content); -#endif - - return userInfo; - } - - throw new Exception("User info could not parsed."); - } - } -} \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UserInfoParser.cs.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UserInfoParser.cs.meta deleted file mode 100644 index ec32329b..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Runtime/Utils/UserInfoParser.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6b51883b6ca43484ebe2eeb1103d43e3 -timeCreated: 1664199443 \ No newline at end of file diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Third Party Notices.md b/Assets/Thirdweb/Plugins/Authentication for Unity/Third Party Notices.md deleted file mode 100644 index 637aea9c..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Third Party Notices.md +++ /dev/null @@ -1,17 +0,0 @@ -This package contains third-party software components governed by the license(s) indicated below: ---------- - -Component Name: Newtonsoft.Json - -The MIT License (MIT) - -Copyright (c) 2007 James Newton-King - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ---------- - diff --git a/Assets/Thirdweb/Plugins/Authentication for Unity/Third Party Notices.md.meta b/Assets/Thirdweb/Plugins/Authentication for Unity/Third Party Notices.md.meta deleted file mode 100644 index d68b8f58..00000000 --- a/Assets/Thirdweb/Plugins/Authentication for Unity/Third Party Notices.md.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 4cd5a26818ceca046a2217cd9add4ea4 -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From 2d24586e32dcca9aa8386ecc696f6b043be121f2 Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Mon, 16 Oct 2023 13:16:59 +0300 Subject: [PATCH 3/3] 60s timeout --- Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs | 2 +- Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs b/Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs index 4b28b77a..72fc727a 100644 --- a/Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs +++ b/Assets/Thirdweb/Core/Scripts/Browser/AndroidBrowser.cs @@ -29,7 +29,7 @@ public async Task Login(string loginUrl, string customScheme, Can try { OpenURL(loginUrl); - var completedTask = await Task.WhenAny(_taskCompletionSource.Task, Task.Delay(TimeSpan.FromSeconds(30))); + var completedTask = await Task.WhenAny(_taskCompletionSource.Task, Task.Delay(TimeSpan.FromSeconds(60))); if (completedTask == _taskCompletionSource.Task) { return await _taskCompletionSource.Task; diff --git a/Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs b/Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs index 11919faf..4bc71821 100644 --- a/Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs +++ b/Assets/Thirdweb/Core/Scripts/Browser/IOSBrowser.cs @@ -30,7 +30,7 @@ public async Task Login(string loginUrl, string customScheme, Can try { OpenURL(loginUrl); - var completedTask = await Task.WhenAny(_taskCompletionSource.Task, Task.Delay(TimeSpan.FromSeconds(30))); + var completedTask = await Task.WhenAny(_taskCompletionSource.Task, Task.Delay(TimeSpan.FromSeconds(60))); if (completedTask == _taskCompletionSource.Task) { return await _taskCompletionSource.Task;