{"id":16687175,"url":"https://github.com/redth/plugin.socialauth","last_synced_at":"2025-08-07T16:13:22.335Z","repository":{"id":137487503,"uuid":"90276411","full_name":"Redth/Plugin.SocialAuth","owner":"Redth","description":"Xamarin Plugin to assist with Native social authentication","archived":false,"fork":false,"pushed_at":"2020-03-17T17:16:33.000Z","size":464,"stargazers_count":6,"open_issues_count":2,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-04T00:15:09.132Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Redth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-04T15:01:04.000Z","updated_at":"2021-04-21T23:40:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"a9ba8a1b-0061-4b84-889e-7224ad5d1e23","html_url":"https://github.com/Redth/Plugin.SocialAuth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Redth/Plugin.SocialAuth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FPlugin.SocialAuth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FPlugin.SocialAuth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FPlugin.SocialAuth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FPlugin.SocialAuth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Redth","download_url":"https://codeload.github.com/Redth/Plugin.SocialAuth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Redth%2FPlugin.SocialAuth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269286325,"owners_count":24391430,"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","status":"online","status_checked_at":"2025-08-07T02:00:09.698Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-12T15:08:05.706Z","updated_at":"2025-08-07T16:13:22.300Z","avatar_url":"https://github.com/Redth.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Plugin.SocialAuth\n\nXamarin Social Authentication with Native SDK's and OAuth through SFSafariViewController and Android Custom Tabs.\n\n**NOTE: This is currently a work in progress...**\n\nSocial authentication in mobile apps has evolved since the beginning of Xamarin.  Providers such as Google and Facebook offer native SDK's to help deliver a delightful user experience when authentication with their platforms.\n\niOS and Android have both recently provided their own extensions of the operating system browser (`SFSafariViewController` and `CustomTabs`) and now prefer (and in some cases such as Google, require) that you use them for enabling social authentication in your apps. \n\nPlugin.SocialAuth aims to provide you with the latest and greatest options for adding social authentication to your Xamarin apps as easily as possible.\n\n\n### What's missing?\n\n - NuGet packages\n - Automatic handling of refreshing of access tokens in OAuth2\n - More known provider support with specific authentication implementations (Fitbit, Meetup, etc).\n - Windows UWP support!\n - Helpers to create Authenticated `HttpRequestMessage` objects for further user with provider API's\n\n## Supported Providers\n\nYou can pick and choose which providers you want to use on each platform.\n\n### iOS\n\n| Provider        | Implementation                 | NuGet Package                  |\n|-----------------|--------------------------------|--------------------------------|\n| Facebook        | LoginKit Native SDK*           | Plugin.SocialAuth.Facebook.iOS |\n| Google          | Sign-In Native SDK             | Plugin.SocialAuth.Google.iOS   |\n| Twitter         | OAuth `SFSafariViewController` | Plugin.SocialAuth.Twitter.iOS  |\n| OAuth1 \u0026 OAuth2 | OAuth `SFSafariViewController` | Plugin.Social.Auth.iOS         |\n\n\n### Android\n\n| Provider        | Implementation                        | NuGet Package                      |\n|-----------------|---------------------------------------|------------------------------------|\n| Facebook        | Native Android SDK*                   | Plugin.SocialAuth.Facebook.Droid   |\n| Google          | Google Play services Auth SDK*        | Plugin.SocialAuth.Google.Droid     |\n| Twitter         | OAuth Android Support CustomTabs SDK* | Plugin.SocialAuth.Twitter.Droid    |\n| OAuth1 \u0026 OAuth2 | OAuth Android Support CustomTabs SDK* | Plugin.SocialAuth.Droid.CustomTabs |\n\n[*] All of the Native SDK Provider options are packaged as separate NuGet packages in case you don't need them in your app (or want to use one of the OAuth providers instead of the Native SDK implementation), so that you don't incur their size or dependencies in such a case.\n\n\n\n\n## How does it work? \n\nThe core API is available in a `.NET Standard 1.4` library via NuGet.\n\nThere is a shared instance of `SocialAuthManager` which you can access to authenticate.  Here is an example of invoking the Native Facebook SDK authentication flow:\n\n```csharp\n// See if we previously logged in with any particular account\nvar existingAccount = SocialAuthManager.Current.AccountStore.FindAnyAccount(ProviderType.Facebook);\n\n// Authenticate with Facebook's native SDK\nvar account = await SocialAuthManager.Current.AuthenticateFacebookAsync(new FacebookAuthOptions(), existingAccount?.Id);\n```\n\nIn the above sample, we are first trying to look up _any_ existing Facebook account from our local `AccountStore` in order to pass the `Id` into the Authentication call.  \n\nPlugin.SocialAuth takes care of caching authenticated accounts for you so that future Authentication calls will avoid the UI authorization flow, if the cached account is unexpired and valid.\n\nWe can just omitt the `Id` in the Authentication call if we don't care to look in the local cache first.\n\n\n\n## Setup / Init\n\nBefore we can actually use the sample above, and call the Authentication methods, we need to do some setup.\n\nAdditionally each provider and platform may require specific application configuration.\n\n\n### iOS\n\nIn your `AppDelegate`'s `FinishedLaunching` method we need to add some calls to Init and Register our providers:\n\n```csharp\n// Init the things\nSocialAuth.Init();\nFacebookAuthProvider.Init(SocialKeys.FACEBOOK_APP_ID;\n```\n\nSome providers like Facebook require a specific `Init` call like in the first block above, while others do not.\n\nNext, we need to register the different provider _implementations_ we would like to associate with the provider types:\n\n```csharp\n//Register custom handlers\nSocialAuthManager.Current.RegisterProvider\u003cFacebookAuthProvider\u003e(ProviderType.Facebook);\nSocialAuthManager.Current.RegisterProvider\u003cGoogleAuthProvider\u003e(ProviderType.Google);\nSocialAuthManager.Current.RegisterProvider\u003cTwitterSafariServicesAuthProvider\u003e(ProviderType.Twitter);\nSocialAuthManager.Current.RegisterProvider\u003cOAuth2SafariServicesProvider\u003e(\"fitbit\");\n```\n\nYou can see it's possible to use a custom `providerTypeId`, but the `ProviderType` enum will contain most common providers.\n\nNotice the generic type argument of the `RegisterProvider` call contains the _implementation_ type that will be used when the authentication call is made for the given provider type.\n\nThis means it's possible to register an `OAuth2SafariServicesProvider` as the implementation for `ProviderType.Facebook` if you'd rather use `SFSafariViewController` instead of the Native Facebook SDK.\n\nSome providers will require relaying calls from your `AppDelegate.OpenUrl` override to `SocialAuthManager.OpenUrl`.  You should add the following code to your `AppDelegate`:\n\n```csharp\n// We need to relay open url calls to social auth\npublic override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)\n{\n\tif (Plugin.SocialAuth.iOS.SocialAuth.OpenUrl(application, url, sourceApplication, annotation))\n\t\treturn true;\n\n\treturn false;\n}\n```\n\n### Android\nAndroid is very similar to iOS, but instead, you should call your `Init`'s and `RegisterProvider`'s in the `MainActivity` of your app.\n\nAndroid also requires that we relay our current `Activity`'s `OnActivityResult` (if you're using Xamarin.Forms this should be in your `MainActivity`):\n\n```csharp\n// Pass OnActivityResult back into social auth\nprotected override void OnActivityResult(int requestCode, Result resultCode, Intent data)\n{\n\tbase.OnActivityResult(requestCode, resultCode, data);\n\n\tPlugin.SocialAuth.Droid.SocialAuth.OnActivityResult(requestCode, resultCode, data);\n}\n```\n\nAlso, in some cases where we will receive callbacks into our own application (eg: in the case of `OAuth1CustomTabsAuthProvider` and `OAuth2CustomTabsProvider`), we need to setup an `Activity` subclassing `Plugin.SocialAuth.Droid.CustomTabs.OAuthCallbackActivity` which registers itself with an `IntentFilter` handling the `DataScheme` of your Callback/Redirect URL that you are using with your OAuth provider.  Here's an example that registers the scheme `plugin.socialauth://` and assumes you're passing something like `plugin.socialauth://twitter` to your authentication provider as your callback/redirect URL:\n\n```csharp\n// We need this callback to redirect callbacks into our app to SocialAuth to handle\n[Activity(NoHistory = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop)]\n[IntentFilter(new[] { Intent.ActionView },\n\t\t\t  Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = \"plugin.socialauth\")]\npublic class SocialAuthOAuth1CallbackActivity : Plugin.SocialAuth.Droid.CustomTabs.OAuthCallbackActivity\n{\n}\n```\n\n\n## Provider Specific Setup\n\nEach social provider will have specific guides to setting up keys/credentials and in some cases your app configuration for iOS/Android in order to make authentication work.  \n\n### Facebook\n\nYou will need to visit [Facebook for Developers](https://developers.facebook.com/) to setup an Application.  Additionally there are instructions for setting up iOS and Android app login:\n\n - [Facebook Login for iOS Quickstart](https://developers.facebook.com/docs/facebook-login/ios)\n - [Facebook Login for Android](https://developers.facebook.com/docs/facebook-login/android)\n\nNOTE: Facebook Login for iOS requires that you add specific URL schemes to your _Info.plist_ file.\n\nNOTE: Facebook Login for Android requires that you add some specific items to your _AndroidManifest.xml_ file.  Additionally you will need to provide `.keystore` hashes in the Facebook Developer portal under your Android App settings.  Be sure to add hashes for your _debug.keystore_ as well as the _.keystore_ used for signing Play store builds.\n\n\n### Google\n\nYou will need to visit [Google API Developer Console](https://console.developers.google.com/) to create an application and Credentials to use in your apps.  There are specific guides for iOS and Android to setting up your app as well:\n\n - [Google Sign-In for iOS](https://developers.google.com/identity/sign-in/ios/start-integrating)\n - [Google Sign-In for Android](https://developers.google.com/identity/sign-in/android/start-integrating)\n\nNOTE: Google for iOS requires that you add some specific items to your _Info.plist_ file.  Additionally you will need to add a `GoogleService-Info.plist` in your iOS app project.\n\nNOTE: Google for Android is a bit tricky when it comes to setting up your keys in the Google API Developer Console.  You will want to setup an Android key credential for the `ClientId` but for the `ServerClientId` you will want to setup an OAuth web application type credential.\n\n\n\n## Caching and Token Refresh\nThe `SocialAuthManager` handles caching account information including tokens and in some provider cases, basic profile info, if you pass in the `Id` of the `IAccount` returned from a previous Authentication call.  Omitting this parameter will cause the cache to be skipped.\n\nThis means when you call the `AuthenticateAsync (..)` method, if there are still unexpired / valid tokens in your cache, the `Account` object will be immediately returned instead of going through the user sign in flow again.\n\nIf there is no associated account already signed in and cached, calling `AuthenticateAsync (..)` will cause the sign in flow to begin.\n\nBoth Google's and Facebook's Native SDKs additionally manage their own cache.  Plugin.SocialAuth will attempt to use these caches if its own cache is invalid.  In some cases, this means the user will not need to be asked to sign in (e.g.: Facebook can sign in automatically if you've already granted the application access with the same account on another device). \n\nIn the case of OAuth2 providers, if there is a `refresh_token` in the cache and the `access_token` is expired, a call to refresh the access token will be attempted.  If successful, the UI authentication flow can be avoided and the new access token and refresh tokens will be cached for future use.\n\n\n### Security\n\nOn both iOS and Android, account caches are stored using platform specific secure storage API's.\n\n\n## License\n\nCopyright (c) 2017 Jonathan Dick\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredth%2Fplugin.socialauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredth%2Fplugin.socialauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredth%2Fplugin.socialauth/lists"}