{"id":21024507,"url":"https://github.com/clancey/simpleauth","last_synced_at":"2025-04-13T05:07:29.001Z","repository":{"id":35745861,"uuid":"40024976","full_name":"Clancey/SimpleAuth","owner":"Clancey","description":"The Simplest way to Authenticate and make Rest API calls in .Net","archived":false,"fork":false,"pushed_at":"2022-12-07T21:19:54.000Z","size":1921,"stargazers_count":174,"open_issues_count":29,"forks_count":48,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-13T05:07:24.965Z","etag":null,"topics":["authentication","oauth2-client","uwp","windows","xamarin","xamarin-android","xamarin-forms","xamarin-ios","xamarin-mac"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Clancey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-31T21:07:50.000Z","updated_at":"2025-02-01T16:22:21.000Z","dependencies_parsed_at":"2023-01-16T05:15:20.521Z","dependency_job_id":null,"html_url":"https://github.com/Clancey/SimpleAuth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clancey%2FSimpleAuth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clancey%2FSimpleAuth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clancey%2FSimpleAuth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clancey%2FSimpleAuth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clancey","download_url":"https://codeload.github.com/Clancey/SimpleAuth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665747,"owners_count":21142123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","oauth2-client","uwp","windows","xamarin","xamarin-android","xamarin-forms","xamarin-ios","xamarin-mac"],"created_at":"2024-11-19T11:26:55.913Z","updated_at":"2025-04-13T05:07:28.982Z","avatar_url":"https://github.com/Clancey.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Auth\n\nEvery API needs authentication, yet no developer wants to deal with authentication. Simple Auth embeds authentication into the API so you dont need to deal with it. Most importantly it works great with traditional Xamarin and Xamarin.Forms\n  \n  [![Join the chat at https://gitter.im/simpleauth/community](https://badges.gitter.im/simpleauth/community.svg)](https://gitter.im/simpleauth/community?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nAndroid: [![Android Build status](https://build.appcenter.ms/v0.1/apps/7e5acfa7-b0fb-4468-8e0a-f947abcded95/branches/master/badge)](https://appcenter.ms)\n\niOS/MacOS: [![Build status](https://build.appcenter.ms/v0.1/apps/fabfc2aa-5ed3-420b-b257-343b158c176e/branches/master/badge)](https://appcenter.ms)\n\n\n# General information\n\n\n## Available on Nuget\n\n[Clancey.SimpleAuth](https://www.nuget.org/packages/Clancey.SimpleAuth/)\n\n## Providers\n\n### Current Built in Providers\n\n* Azure Active Directory\n* Amazon\n* Dropbox\n* Facebook\n* Github\n* Google\n* Instagram\n* Linked In\n* Microsoft Live Connect\n* Twitter\n\nSimple auth ships with some built in providers so you just need to add your keys and scopes.\n\n```cs\nvar scopes = new[]\n{\n\t\"https://www.googleapis.com/auth/userinfo.email\",\n\t\"https://www.googleapis.com/auth/userinfo.profile\"\n};\nvar api = new GoogleApi(\"google\",\n\t   \"clientid\",\n\t   \"clientsecret\")\n{\n\tScopes = scopes,\n};\n\nvar account = await api.Authenticate();\n```\n\n\n## Restful Api Requests\n\nRestful Api Requests couldnt be simpler\n\n```cs\nvar song = await api.Get\u003cSong\u003e(\"http://myapi/Song/\",songId);\n```\n\nParamaters can be added as part of the path\n\n```cs\nvar todoItem = await api.Get\u003cTodoItem\u003e(\"http://myapi/user/{UserId}/TodoItem\",new Dictionary\u003cstring,string\u003e{[\"UserId\"] = \"1\", [\"itemID\"] = \"22\"});\n```\nGenerates the following Url:\n\n```cs\nhttp://myapi/user/1/TodoItem?itemID=22\n```\n\n\n## Attribute your Api Requests (Optional)\n\n```cs\n[Path(\"/pet\")]\n[ContentType(\"application/json\")]\n[Accepts(\"application/json\")]\npublic virtual Task AddPet(Pet body) {\n    return Post( body);\n}\n```\n\n\n# iOS/Mac Specific\n\n## OnePassword Support (iOS)\n\nOne password support is for iOS Only.  \nSimply add the project or the Nuget\n\n[Clancey.SimpleAuth.OnePassword](https://www.nuget.org/packages/Clancey.SimpleAuth.OnePassword/)\n\nThen call the following line in your iOS project prior to calling api.Authenticate();\n```cs\nSimpleAuth.OnePassword.Activate();\n```\n\n## Native Twitter Support via Twitter App\nYou can use the Twitter app to authenticate with SimpleAuth on iOS. \n\nAdd the following to your Info.Plist\n```\n// Info.plist\n\u003ckey\u003eCFBundleURLTypes\u003c/key\u003e\n\u003carray\u003e\n  \u003cdict\u003e\n    \u003ckey\u003eCFBundleURLSchemes\u003c/key\u003e\n    \u003carray\u003e\n      \u003cstring\u003etwitterkit-\u003cconsumerKey\u003e\u003c/string\u003e\n    \u003c/array\u003e\n  \u003c/dict\u003e\n\u003c/array\u003e\n\u003ckey\u003eLSApplicationQueriesSchemes\u003c/key\u003e\n\u003carray\u003e\n    \u003cstring\u003etwitter\u003c/string\u003e\n    \u003cstring\u003etwitterauth\u003c/string\u003e\n\u003c/array\u003e\n```\n\nThen call the following line in your iOS AppDelegate FinishedLaunching method;\n\n```cs\nSimpleAuth.Providers.Twitter.Init();\n```\n\nAlso add the following override in your AppDelegate\n\n```cs\npublic override bool OpenUrl (UIApplication app, NSUrl url, NSDictionary options)\n{\n\tif (SimpleAuth.Native.OpenUrl(app, url, options))\n\t\treturn true;\n\treturn base.OpenUrl(app,url,options);\n}\n```\n\n## Native Facebook Support via iOS SDK \n  \nSimply add the project or the Nuget\n\n[Clancey.SimpleAuth.Facebook.iOS](https://www.nuget.org/packages/Clancey.SimpleAuth.Facebook.iOS/)\n\nThe Facebook SDK requires you modify your info.plist : https://components.xamarin.com/gettingstarted/facebookios\n\nThen call the following line in your iOS AppDelegate FinishedLaunching method;\n\n```cs\nSimpleAuth.Providers.Facebook.Init(app, options);\n```\n\nAlso add the following override in your AppDelegate\n\n```cs\npublic override bool OpenUrl (UIApplication app, NSUrl url, NSDictionary options)\n{\n\tif (SimpleAuth.Native.OpenUrl(app, url, options))\n\t\treturn true;\n\treturn base.OpenUrl(app,url,options);\n}\n```\n\n## Native Google Support via iOS SDK\n\n[Clancey.SimpleAuth.Google.iOS](https://www.nuget.org/packages/Clancey.SimpleAuth.Google.iOS/)\n\nThe Google SDK can do Cross-Client Login.  This allows you to get tokens for the server, with one login.\n\nTo use Cross-client you need to set the ServerClientId on the GoogleApi. \n\nCall the following in your FinishedLaunching Method;\n\n```cs\nSimpleAuth.Providers.Google.Init()\n```\n\nAlso add the following to your AppDelegate\n\n\n```cs\npublic override bool OpenUrl (UIApplication app, NSUrl url, NSDictionary options)\n{\n\tif (SimpleAuth.Native.OpenUrl(app, url, options))\n\t\treturn true;\n\treturn base.OpenUrl(app,url,options);\n}\n```\n\nIf you need Cross-client authentication\n\n```cs\nvar api = new GoogleApi(\"google\",\"client_id\"){\n\tServerClientId = \"server_client_id\"\"\n};\nvar account = await api.Authenticate ();\nvar serverToken = account.UserData [\"ServerToken\"];\n```\n\n### Troubleshooting\n\n```\nSystem.Exception: Error Domain=com.google.GIDSignIn Code=-2 \"keychain error\" UserInfo={NSLocalizedDescription=keychain error}\n```\n\nUnder the iOS Build Signing, Custom Entitlements: make sure an entitlement.plist is set \n\n\n## Native SFSafariViewController iOS/MacOS\n\nSFSafariViewController Allows users to use Safari to login, instead of embedded webviews.\n\nGoogle now requires this mode and is enabled by default for Google Authentication on iOS/MacOS.\n\nTo use the Native Safari Authenticator, you are required to add the following snippet in your AppDelegate (**iOS Only**)\n\n```cs\npublic override bool OpenUrl (UIApplication app, NSUrl url, NSDictionary options)\n{\n\tif (SimpleAuth.Native.OpenUrl(app, url, options))\n\t\treturn true;\n\treturn base.OpenUrl(app,url,options);\n}\n\n```\n\nYou are also required to add the following to add a CFBundleURLSchemes to your info.plist \n\nFor Google: com.googleusercontent.apps.YOUR_CLIENT_ID\n\n```\n\t\u003ckey\u003eCFBundleURLTypes\u003c/key\u003e\n\t\u003carray\u003e\n\t\t\u003cdict\u003e\n\t\t\t\u003ckey\u003eCFBundleURLSchemes\u003c/key\u003e\n\t\t\t\u003carray\u003e\n\t\t\t\t\u003cstring\u003ecom.googleusercontent.apps.YOURCLIENTID\u003c/string\u003e\n\t\t\t\u003c/array\u003e\n\t\t\t\u003ckey\u003eCFBundleURLName\u003c/key\u003e\n\t\t\t\u003cstring\u003egoogleLogin\u003c/string\u003e\n\t\t\u003c/dict\u003e\n\t\u003c/array\u003e\n\t\n```\n\n\n\n# Android\n\n## Google Sign-In on Android\n\nSimple Auth supports the native Google Sign-in for Android.\n\n1. Add the nuget \n[Clancey.SimpleAuth.Google.Droid](https://www.nuget.org/packages/Clancey.SimpleAuth.Google.Droid/)\n2. Create OAuth Client Id (Web Application): [Link](https://console.developers.google.com/apis/credentials)\n3. Create and OAuth Android app: [Link](https://console.developers.google.com/apis/credentials)\n\t* Sign your app using the same Keystore\n4. Use both the Web Application ClientID. ClientSecret is not required but reccomended.\n5. Add the following code to your Main Activity\n\n\t```cs\n\tprotected override void OnCreate(Bundle bundle)\n\t{\n\t\tbase.OnCreate(bundle);\n\t\tSimpleAuth.Providers.Google.Init(this.Application);\n\t\t//The rest of your initialize code\n\t}\n\t\n\tprotected override void OnActivityResult(int requestCode, Result resultCode, Intent data)\n\t{\n\t   base.OnActivityResult(requestCode, resultCode, data);\n\t\tSimpleAuth.Native.OnActivityResult (requestCode,resultCode,data); \n\t}\n\t```\n\nIf you need Cross-Client authentication pass your ServerClientId into the google api\n\n```cs\nvar api = new GoogleApi(\"google\",\"client_id\"){\n\tServerClientId = \"server_client_id\"\"\n};\nvar account = await api.Authenticate ();\nvar serverToken = account.UserData [\"ServerToken\"];\n```\n\n\n### Troubleshooting\nIf you get:\n ```Unable to find explicit activity class {com.google.android.gms.auth.api.signin.internal.SignInHubActivity}; have you declared this activity in your AndroidManifest.xml?```\n\nAdd the following to your AndroidManifest.xml\n\n```\n\u003cactivity android:name=\"com.google.android.gms.auth.api.signin.internal.SignInHubActivity\"\n\t\tandroid:screenOrientation=\"portrait\"\n\t\tandroid:windowSoftInputMode=\"stateAlwaysHidden|adjustPan\" /\u003e\n\t\u003c/application\u003e\n```\n### Status Code 12501 (unknown) Your app signing or tokens are invalid\n1. Check your app is signed with the same KeyStore noted in for your android app [Link](https://console.developers.google.com/apis/credentials)\n2. Regenerate new OAuth 2 Client id, create the WebApplication kind.\n\n## Native Facebook for Android\n\nSimple Auth supports the native Facebook SDK for Android.\n\n1. Add the nuget \n[Clancey.SimpleAuth.Facebook.Droid](https://www.nuget.org/packages/Clancey.SimpleAuth.Facebook.Droid/)\n2. Create an Android App: [Link](https://developers.facebook.com/docs/facebook-login/android)\n3. Add the following to your String.xml in Resources/values. If your appId was 1066763793431980\n\t```\n\t\u003cstring name=\"facebook_app_id\"\u003e1066763793431980\u003c/string\u003e\n\t\u003cstring name=\"fb_login_protocol_scheme\"\u003efb1066763793431980\u003c/string\u003e\n\t```\n4. Add a meta-data element to the application element: \n\t```\n\t[assembly: MetaData(\"com.facebook.sdk.ApplicationId\", Value = \"@string/facebook_app_id\")]\n\t```\n5. \tAdd FacebookActivity to your AndroidManifest.xml:\n\t```\n\t\u003cactivity android:name=\"com.facebook.FacebookActivity\"\n          android:configChanges=\n                 \"keyboard|keyboardHidden|screenLayout|screenSize|orientation\"\n          android:label=\"@string/app_name\" /\u003e          \n\t\u003cactivity\n\t    android:name=\"com.facebook.CustomTabActivity\"\n\t    android:exported=\"true\"\u003e\n\t    \u003cintent-filter\u003e\n\t        \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n\t        \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n\t        \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n\t        \u003cdata android:scheme=\"@string/fb_login_protocol_scheme\" /\u003e\n\t    \u003c/intent-filter\u003e\n\t\u003c/activity\u003e\n\t```\n6. Add the following code to your Main Activity\n\n\t```cs\n\tprotected override void OnCreate(Bundle bundle)\n\t{\n\t\tbase.OnCreate(bundle);\n\t\tSimpleAuth.Providers.Google.Init(this.Application);\n\t\t//The rest of your initialize code\n\t}\n\t\n\tprotected override void OnActivityResult(int requestCode, Result resultCode, Intent data)\n\t{\n\t   base.OnActivityResult(requestCode, resultCode, data);\n\t\tNative.OnActivityResult (requestCode,resultCode,data); \n\t}\n\t```\n\n## CustomTabs for Android\n\nSimpleAuth supports using Custom Tabs for authorization.\n\n1. Add the nuget [Clancey.SimpleAuth.Droid.CustomTabs](https://www.nuget.org/packages/Clancey.SimpleAuth.Droid.CustomTabs)\n2. In your Droid project, create a subclass of SimpleAuthCallbackActivity to handle your url scheme, replacing the value of DataScheme with the scheme you used for the redirectUrl parameter of the Api constructor \n\n\t```cs\n    [Activity(NoHistory = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop)]\n    [IntentFilter(new [] { Intent.ActionView},\n        Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable},\n        DataScheme = \"YOUR CUSTOM SCHEME\")]\n    public class MyCallbackActivity : SimpleAuthCallbackActivity\n    {\n    }\n\t```\n\n## .Net Core\n\nYou will need to implement an AuthStorage\n\n```cs\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Security.Cryptography;\nusing System.Text;\nusing System.Linq;\n\nnamespace SimpleAuth\n{\n\tpublic class AuthStorage : IAuthStorage\n\t{\n\t\tprivate const int Keysize = 128;\n\t\tprivate const int DerivationIterations = 1000;\n\n\t\tpublic static string EncryptString(string plainText, string passPhrase)\n\t\t{\n\t\t\tvar saltStringBytes = Generate256BitsOfRandomEntropy();\n\t\t\tvar ivStringBytes = Generate256BitsOfRandomEntropy();\n\t\t\tvar plainTextBytes = Encoding.UTF8.GetBytes(plainText);\n\t\t\tusing (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations))\n\t\t\t{\n\t\t\t\tvar keyBytes = password.GetBytes(Keysize / 8);\n\t\t\t\tusing (var symmetricKey = new RijndaelManaged())\n\t\t\t\t{\n\t\t\t\t\tsymmetricKey.BlockSize = Keysize;\n\t\t\t\t\tsymmetricKey.Mode = CipherMode.CBC;\n\t\t\t\t\tsymmetricKey.Padding = PaddingMode.PKCS7;\n\t\t\t\t\tusing (var encryptor = symmetricKey.CreateEncryptor(keyBytes, ivStringBytes))\n\t\t\t\t\t{\n\t\t\t\t\t\tusing (var memoryStream = new MemoryStream())\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tusing (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tcryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);\n\t\t\t\t\t\t\t\tcryptoStream.FlushFinalBlock();\n\t\t\t\t\t\t\t\t// Create the final bytes as a concatenation of the random salt bytes, the random iv bytes and the cipher bytes.\n\t\t\t\t\t\t\t\tvar cipherTextBytes = saltStringBytes;\n\t\t\t\t\t\t\t\tcipherTextBytes = cipherTextBytes.Concat(ivStringBytes).ToArray();\n\t\t\t\t\t\t\t\tcipherTextBytes = cipherTextBytes.Concat(memoryStream.ToArray()).ToArray();\n\t\t\t\t\t\t\t\tmemoryStream.Close();\n\t\t\t\t\t\t\t\tcryptoStream.Close();\n\t\t\t\t\t\t\t\treturn Convert.ToBase64String(cipherTextBytes);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpublic static string DecryptString(string cipherText, string passPhrase)\n\t\t{\n\t\t\tvar cipherTextBytesWithSaltAndIv = Convert.FromBase64String(cipherText);\n\t\t\tvar saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize / 8).ToArray();\n\t\t\tvar ivStringBytes = cipherTextBytesWithSaltAndIv.Skip(Keysize / 8).Take(Keysize / 8).ToArray();\n\t\t\tvar cipherTextBytes = cipherTextBytesWithSaltAndIv.Skip((Keysize / 8) * 2).Take(cipherTextBytesWithSaltAndIv.Length - ((Keysize / 8) * 2)).ToArray();\n\n\t\t\tusing (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations))\n\t\t\t{\n\t\t\t\tvar keyBytes = password.GetBytes(Keysize / 8);\n\t\t\t\tusing (var symmetricKey = new RijndaelManaged())\n\t\t\t\t{\n\t\t\t\t\tsymmetricKey.BlockSize = Keysize;\n\t\t\t\t\tsymmetricKey.Mode = CipherMode.CBC;\n\t\t\t\t\tsymmetricKey.Padding = PaddingMode.PKCS7;\n\t\t\t\t\tusing (var decryptor = symmetricKey.CreateDecryptor(keyBytes, ivStringBytes))\n\t\t\t\t\t{\n\t\t\t\t\t\tusing (var memoryStream = new MemoryStream(cipherTextBytes))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tusing (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvar plainTextBytes = new byte[cipherTextBytes.Length];\n\t\t\t\t\t\t\t\tvar decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);\n\t\t\t\t\t\t\t\tmemoryStream.Close();\n\t\t\t\t\t\t\t\tcryptoStream.Close();\n\t\t\t\t\t\t\t\treturn Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tprivate static byte[] Generate256BitsOfRandomEntropy()\n\t\t{\n\t\t\tvar randomBytes = new byte[16];\n\t\t\tusing (var rngCsp = new RNGCryptoServiceProvider())\n\t\t\t{\n\t\t\t\trngCsp.GetBytes(randomBytes);\n\t\t\t}\n\t\t\treturn randomBytes;\n\t\t}\n\n\t\tstatic string CalculateMD5Hash(string input)\n\t\t{\n\t\t\tvar md5 = MD5.Create();\n\n\t\t\tvar inputBytes = Encoding.ASCII.GetBytes(input);\n\t\t\tvar hash = md5.ComputeHash(inputBytes);\n\t\t\tvar sb = new StringBuilder();\n\n\t\t\tfor (int i = 0; i \u003c hash.Length; i++)\n\t\t\t{\n\t\t\t\tsb.Append(hash[i].ToString(\"X2\"));\n\t\t\t}\n\n\t\t\treturn sb.ToString();\n\n\t\t}\n\n\t\tpublic void SetSecured(string identifier, string value, string clientId, string clientSecret, string sharedGroup)\n\t\t{\n\t\t\tvar key = $\"{clientId}-{identifier}-{clientId}-{sharedGroup}\";\n\t\t\tvar newKey = CalculateMD5Hash(key);\n\t\t\tvar encrypted = EncryptString(value, clientSecret);\n\t\t\tPlugin.Settings.CrossSettings.Current.AddOrUpdateValue(newKey, encrypted);\n\t\t}\n\n\t\tpublic string GetSecured(string identifier, string clientId, string clientSecret, string sharedGroup)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\tvar key = $\"{clientId}-{identifier}-{clientId}-{sharedGroup}\";\n\t\t\t\tvar newKey = CalculateMD5Hash(key);\n\t\t\t\tvar cryptText = Plugin.Settings.CrossSettings.Current.GetValueOrDefault(newKey, \"\");\n\t\t\t\treturn DecryptString(cryptText, clientSecret);\n\t\t\t}\n\t\t\tcatch (Exception ex)\n\t\t\t{\n\t\t\t\t//Console.WriteLine(ex);\n\t\t\t}\n\t\t\treturn null;\n\t\t}\n\t}\n}\n\n```\n\nFor console apps, you will also need to implement the Authenticators:\n\nBasic Auth\n```cs\nusing System;\nusing System.Security;\nusing System.Threading.Tasks;\nnamespace SimpleAuth\n{\n    public class BasicAuthController\n    {\n        readonly IBasicAuthenicator authenticator;\n\n        public BasicAuthController(IBasicAuthenicator authenticator)\n        {\n            this.authenticator = authenticator;\n        }\n\n\n        public async Task\u003cTuple\u003cstring, string\u003e\u003e GetCredentials(string title, string details = \"\")\n        {\n            try\n            {\n                Console.WriteLine(\"******************\");\n                Console.WriteLine(title);\n                Console.WriteLine(details);\n                Console.WriteLine(\"******************\");\n                Console.WriteLine(\"Enter Username:\");\n                var username = Console.ReadLine();\n                Console.WriteLine(\"Enter Password:\");\n                var password = GetPassword();\n\n                var result = new Tuple\u003cstring, string\u003e(username, password);\n                try\n                {\n                    bool success = false;\n                    var basic = authenticator;\n                    if (basic != null)\n                    {\n                        success = await basic.VerifyCredentials(result.Item1, result.Item2);\n                    }\n                    if (!success)\n                        throw new Exception(\"Invalid Credentials\");\n                }\n                catch (Exception ex)\n                {\n                    result = await GetCredentials(title, $\"Error: {ex.Message}\");\n                }\n                return result;\n            }\n            catch (TaskCanceledException)\n            {\n                authenticator.OnCancelled();\n                return null;\n            }\n        }\n        public string GetPassword()\n        {\n            var pwd = \"\";\n            while (true)\n            {\n                ConsoleKeyInfo i = Console.ReadKey(true);\n                if (i.Key == ConsoleKey.Enter)\n                {\n                    break;\n                }\n                else if (i.Key == ConsoleKey.Backspace)\n                {\n                    if (pwd.Length \u003e 0)\n                    {\n                        pwd.Remove(pwd.Length - 1);\n                        Console.Write(\"\\b \\b\");\n                    }\n                }\n                else\n                {\n                    pwd += (i.KeyChar);\n                    Console.Write(\"*\");\n                }\n            }\n            return pwd;\n        }\n    }\n}\n\n```\n\nWeb Authenticator\n```cs\nusing System;\nusing System.Threading.Tasks;\nusing System.Diagnostics;\nusing System.Runtime.InteropServices;\nnamespace SimpleAuth\n{\n    public class WebAuthenticatorController\n    {\n        readonly WebAuthenticator authenticator;\n\n        public WebAuthenticatorController(WebAuthenticator authenticator)\n        {\n            this.authenticator = authenticator;\n        }\n\n\n        public async Task GetCredentials(string title, string details = \"\")\n        {\n            try\n            {\n                var url = await authenticator.GetInitialUrl();\n                Console.WriteLine(\"******************\");\n                Console.WriteLine(title);\n                Console.WriteLine(details);\n                Console.WriteLine($\"Launching Url: \\\"{url}\\\"\");\n                Console.WriteLine(\"******************\");\n                Console.WriteLine(\"Paste the Redirected URL Here:\");\n                OpenBrowser(url);\n                var username = Console.ReadLine();\n\n                try\n                {\n                    bool success = false;\n                    var basic = authenticator;\n                    if (basic != null)\n                    {\n                        success = basic.CheckUrl(new Uri(username), null);\n                    }\n                    if (!success)\n                        throw new Exception(\"Invalid Credentials\");\n                }\n                catch (Exception ex)\n                {\n                    await GetCredentials(title, $\"Error: {ex.Message}\");\n                }\n            }\n            catch (TaskCanceledException)\n            {\n                authenticator.OnCancelled();\n            }\n        }\n\n        public static void OpenBrowser(Uri uri)\n        {\n            OpenBrowser(uri.AbsoluteUri);\n        }\n\n        public static void OpenBrowser(string url)\n        {\n            try\n            {\n                Process.Start(url);\n            }\n            catch\n            {\n                // hack because of this: https://github.com/dotnet/corefx/issues/10361\n                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))\n                {\n                    url = url.Replace(\"\u0026\", \"^\u0026\");\n                    Process.Start(new ProcessStartInfo(\"cmd\", $\"/c start {url}\") { CreateNoWindow = true });\n                }\n                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))\n                {\n                    Process.Start(\"xdg-open\", url);\n                }\n                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))\n                {\n                    Process.Start(\"open\", url);\n                }\n                else\n                {\n                    throw;\n                }\n            }\n        }\n    }\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclancey%2Fsimpleauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclancey%2Fsimpleauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclancey%2Fsimpleauth/lists"}