├── Screenshots
├── Google.png
├── Facebook.png
└── Instagram.png
├── SocialMediaAuthentication
├── AssemblyInfo.cs
├── Models
│ ├── AuthNetwork.cs
│ ├── NetworkAuthData.cs
│ ├── FacebookProfile.cs
│ └── InstagramUser.cs
├── Services
│ ├── IOAuth2Service.cs
│ └── IInstagramApi.cs
├── App.xaml
├── Views
│ ├── SocialLoginPage.xaml.cs
│ ├── HomePage.xaml.cs
│ ├── SocialLoginPage.xaml
│ └── HomePage.xaml
├── App.xaml.cs
├── SocialMediaAuthentication.csproj
└── ViewModels
│ └── SocialLoginPageViewModel.cs
├── SocialMediaAuthentication.iOS
├── Resources
│ ├── ic_fb.png
│ ├── ic_ig.png
│ ├── Default.png
│ ├── ic_fb@2x.png
│ ├── ic_fb@3x.png
│ ├── Default@2x.png
│ ├── Default-568h@2x.png
│ ├── Default-Portrait.png
│ ├── Default-Portrait@2x.png
│ └── LaunchScreen.storyboard
├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ ├── Icon20.png
│ │ ├── Icon29.png
│ │ ├── Icon40.png
│ │ ├── Icon58.png
│ │ ├── Icon60.png
│ │ ├── Icon76.png
│ │ ├── Icon80.png
│ │ ├── Icon87.png
│ │ ├── Icon1024.png
│ │ ├── Icon120.png
│ │ ├── Icon152.png
│ │ ├── Icon167.png
│ │ ├── Icon180.png
│ │ └── Contents.json
│ └── ic_google.imageset
│ │ ├── google_icon.png
│ │ ├── google_icon@2x.png
│ │ ├── google_icon@3x.png
│ │ └── Contents.json
├── Entitlements.plist
├── Main.cs
├── GoogleService-Info.plist
├── Properties
│ └── AssemblyInfo.cs
├── AppDelegate.cs
├── Services
│ └── OAuth2Service.cs
├── Info.plist
└── SocialMediaAuthentication.iOS.csproj
├── SocialMediaAuthentication.Android
├── Resources
│ ├── drawable
│ │ ├── ic_ig.png
│ │ └── ic_google.png
│ ├── mipmap-hdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── mipmap-mdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── mipmap-xhdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── drawable-hdpi
│ │ └── ic_fb.png
│ ├── drawable-ldpi
│ │ └── ic_fb.png
│ ├── drawable-mdpi
│ │ └── ic_fb.png
│ ├── mipmap-xxhdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── mipmap-xxxhdpi
│ │ ├── icon.png
│ │ └── launcher_foreground.png
│ ├── drawable-xhdpi
│ │ └── ic_fb.png
│ ├── drawable-xxhdpi
│ │ └── ic_fb.png
│ ├── drawable-xxxhdpi
│ │ └── ic_fb.png
│ ├── mipmap-anydpi-v26
│ │ ├── icon.xml
│ │ └── icon_round.xml
│ ├── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ ├── layout
│ │ ├── Toolbar.axml
│ │ └── Tabbar.axml
│ └── AboutResources.txt
├── MainApplication.cs
├── Assets
│ └── AboutAssets.txt
├── Properties
│ ├── AndroidManifest.xml
│ └── AssemblyInfo.cs
├── google-services.json
├── MainActivity.cs
├── Services
│ └── OAuth2Service.cs
└── SocialMediaAuthentication.Android.csproj
├── README.md
├── LICENSE
├── SocialMediaAuthentication.sln
└── .gitignore
/Screenshots/Google.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/Screenshots/Google.png
--------------------------------------------------------------------------------
/Screenshots/Facebook.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/Screenshots/Facebook.png
--------------------------------------------------------------------------------
/Screenshots/Instagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/Screenshots/Instagram.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using Xamarin.Forms.Xaml;
2 |
3 | [assembly: XamlCompilation(XamlCompilationOptions.Compile)]
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/ic_fb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Resources/ic_fb.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/ic_ig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Resources/ic_ig.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/Default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Resources/Default.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/ic_fb@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Resources/ic_fb@2x.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/ic_fb@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Resources/ic_fb@3x.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/Default@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Resources/Default@2x.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/Default-568h@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Resources/Default-568h@2x.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/Default-Portrait.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Resources/Default-Portrait.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/drawable/ic_ig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/drawable/ic_ig.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-hdpi/icon.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-mdpi/icon.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-xhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-xhdpi/icon.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/Default-Portrait@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Resources/Default-Portrait@2x.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/drawable-hdpi/ic_fb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/drawable-hdpi/ic_fb.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/drawable-ldpi/ic_fb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/drawable-ldpi/ic_fb.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/drawable-mdpi/ic_fb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/drawable-mdpi/ic_fb.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/drawable/ic_google.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/drawable/ic_google.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-xxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-xxhdpi/icon.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-xxxhdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-xxxhdpi/icon.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/drawable-xhdpi/ic_fb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/drawable-xhdpi/ic_fb.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/drawable-xxhdpi/ic_fb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/drawable-xxhdpi/ic_fb.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/drawable-xxxhdpi/ic_fb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/drawable-xxxhdpi/ic_fb.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon20.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon29.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon40.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon58.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon58.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon60.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon76.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon80.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon80.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon87.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon87.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon1024.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon120.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon152.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon167.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon167.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Icon180.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-hdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-hdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-mdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-mdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-xhdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-xhdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/ic_google.imageset/google_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/ic_google.imageset/google_icon.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-xxhdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-xxhdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/ic_google.imageset/google_icon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/ic_google.imageset/google_icon@2x.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/ic_google.imageset/google_icon@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CrossGeeks/SocialMediaAuthenticationSample/HEAD/SocialMediaAuthentication.iOS/Assets.xcassets/ic_google.imageset/google_icon@3x.png
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-anydpi-v26/icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 | #3F51B5
5 | #303F9F
6 | #FF4081
7 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | SocialMediaAuthentication
4 | 1212486175604889
5 | fb1212486175604889
6 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/mipmap-anydpi-v26/icon_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Models/AuthNetwork.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace SocialMediaAuthentication.Models
3 | {
4 | public class AuthNetwork
5 | {
6 | public string Name { get; set; }
7 |
8 | public string Icon { get; set; }
9 |
10 | public string Background { get; set; }
11 |
12 | public string Foreground { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Entitlements.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | keychain-access-groups
6 |
7 | $(AppIdentifierPrefix)com.crossgeeks.SocialMediaAuthentication
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Services/IOAuth2Service.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace SocialMediaAuthentication.Services
3 | {
4 | public interface IOAuth2Service
5 | {
6 | event EventHandler OnSuccess;
7 | event EventHandler OnError;
8 | event EventHandler OnCancel;
9 |
10 | void Authenticate(string clientId, string scope, Uri authorizeUrl, Uri redirectUrl);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/layout/Toolbar.axml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Services/IInstagramApi.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Http;
3 | using System.Threading.Tasks;
4 | using Refit;
5 |
6 | namespace SocialMediaAuthentication.Services
7 | {
8 | [Headers("Content-Type: application/json")]
9 | public interface IInstagramApi
10 | {
11 | [Get("/v1/users/self/?access_token={accessToken}")]
12 | Task GetUser(string accessToken);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Models/NetworkAuthData.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace SocialMediaAuthentication.Models
4 | {
5 | public class NetworkAuthData
6 | {
7 | public string Id { get; set; }
8 |
9 | public string Name { get; set; }
10 |
11 | public string Logo { get; set; }
12 |
13 | public string Picture { get; set; }
14 |
15 | public string Background { get; set; }
16 |
17 | public string Foreground { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/App.xaml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Views/SocialLoginPage.xaml.cs:
--------------------------------------------------------------------------------
1 | using SocialMediaAuthentication.Services;
2 | using SocialMediaAuthentication.ViewModels;
3 | using Xamarin.Forms;
4 |
5 | namespace SocialMediaAuthentication.Views
6 | {
7 | public partial class SocialLoginPage : ContentPage
8 | {
9 | public SocialLoginPage(IOAuth2Service oAuth2Service)
10 | {
11 | InitializeComponent();
12 | this.BindingContext = new SocialLoginPageViewModel(oAuth2Service);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/layout/Tabbar.axml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/ic_google.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images": [
3 | {
4 | "filename": "google_icon@3x.png",
5 | "scale": "3x",
6 | "idiom": "universal"
7 | },
8 | {
9 | "filename": "google_icon@2x.png",
10 | "scale": "2x",
11 | "idiom": "universal"
12 | },
13 | {
14 | "filename": "google_icon.png",
15 | "scale": "1x",
16 | "idiom": "universal"
17 | }
18 | ],
19 | "info": {
20 | "version": 1,
21 | "author": "xcode"
22 | }
23 | }
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Main.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | using Foundation;
6 | using UIKit;
7 |
8 | namespace SocialMediaAuthentication.iOS
9 | {
10 | public class Application
11 | {
12 | // This is the main entry point of the application.
13 | static void Main(string[] args)
14 | {
15 | // if you want to use a different Application Delegate class from "AppDelegate"
16 | // you can specify it here.
17 | UIApplication.Main(args, null, "AppDelegate");
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Social Media Authentication
3 |
4 | ## Facebook
5 |
6 |
7 |
8 |
9 | Blog post: [Facebook](http://www.xamboy.com/2019/07/23/social-media-authentication-facebook-login-in-xamarin-forms/)
10 |
11 |
12 | ## Instagram
13 |
14 |
15 |
16 |
17 | Blog post: [Instagram](http://www.xamboy.com/2019/08/02/social-media-authentication-instagram-login-in-xamarin-forms/)
18 |
19 | ## Google
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/MainApplication.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Android.App;
3 | using Android.Runtime;
4 | using Plugin.CurrentActivity;
5 |
6 | namespace SocialMediaAuthentication.Droid
7 | {
8 | #if DEBUG
9 | [Application(Debuggable = true)]
10 | #else
11 | [Application(Debuggable = false)]
12 | #endif
13 | public class MainApplication : Application
14 | {
15 | public MainApplication(IntPtr handle, JniHandleOwnership transer)
16 | : base(handle, transer)
17 | {
18 | }
19 |
20 | public override void OnCreate()
21 | {
22 | base.OnCreate();
23 | CrossCurrentActivity.Current.Init(this);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Assets/AboutAssets.txt:
--------------------------------------------------------------------------------
1 | Any raw assets you want to be deployed with your application can be placed in
2 | this directory (and child directories) and given a Build Action of "AndroidAsset".
3 |
4 | These files will be deployed with you package and will be accessible using Android's
5 | AssetManager, like this:
6 |
7 | public class ReadAsset : Activity
8 | {
9 | protected override void OnCreate (Bundle bundle)
10 | {
11 | base.OnCreate (bundle);
12 |
13 | InputStream input = Assets.Open ("my_asset.txt");
14 | }
15 | }
16 |
17 | Additionally, some Android functions will automatically load asset files:
18 |
19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
20 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Models/FacebookProfile.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace SocialMediaAuthentication.Models
4 | {
5 | public class Data
6 | {
7 | [JsonProperty("is_silhouette")]
8 | public bool IsSilhouette { get; set; }
9 | public int Height { get; set; }
10 | public string Url { get; set; }
11 | public int Width { get; set; }
12 | }
13 |
14 | public class Picture
15 | {
16 | public Data Data { get; set; }
17 | }
18 |
19 | public class FacebookProfile
20 | {
21 | public string Email { get; set; }
22 | public string Id { get; set; }
23 | public Picture Picture { get; set; }
24 |
25 | [JsonProperty("last_name")]
26 | public string LastName { get; set; }
27 | [JsonProperty("first_name")]
28 | public string FirstName { get; set; }
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/SocialMediaAuthentication/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using SocialMediaAuthentication.Services;
3 | using SocialMediaAuthentication.Views;
4 | using Xamarin.Forms;
5 | using Xamarin.Forms.Xaml;
6 |
7 | namespace SocialMediaAuthentication
8 | {
9 | public partial class App : Application
10 | {
11 |
12 | public App(IOAuth2Service oAuth2Service)
13 | {
14 | InitializeComponent();
15 |
16 | MainPage = new NavigationPage(new SocialLoginPage(oAuth2Service));
17 | }
18 |
19 | protected override void OnStart()
20 | {
21 | // Handle when your app starts
22 | }
23 |
24 | protected override void OnSleep()
25 | {
26 | // Handle when your app sleeps
27 | }
28 |
29 | protected override void OnResume()
30 | {
31 | // Handle when your app resumes
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 CrossGeeks
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Views/HomePage.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Plugin.FacebookClient;
4 | using Plugin.GoogleClient;
5 | using SocialMediaAuthentication.Models;
6 | using Xamarin.Forms;
7 |
8 | namespace SocialMediaAuthentication.Views
9 | {
10 | public partial class HomePage : ContentPage
11 | {
12 | public HomePage(NetworkAuthData networkAuthData)
13 | {
14 | BindingContext = networkAuthData;
15 | InitializeComponent();
16 | }
17 |
18 | async void OnLogout(object sender, System.EventArgs e)
19 | {
20 | if(BindingContext is NetworkAuthData data)
21 | {
22 | switch(data.Name)
23 | {
24 | case "Facebook":
25 | CrossFacebookClient.Current.Logout();
26 | break;
27 | case "Google":
28 | CrossGoogleClient.Current.Logout();
29 | break;
30 | }
31 |
32 | await Navigation.PopModalAsync();
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/SocialMediaAuthentication.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | true
6 |
7 |
8 |
9 | pdbonly
10 | true
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Models/InstagramUser.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Newtonsoft.Json;
3 |
4 | namespace SocialMediaAuthentication.Models
5 | {
6 | public class InstagramCounts
7 | {
8 | public int Media { get; set; }
9 | public int Follows { get; set; }
10 | [JsonProperty("followed_by")]
11 | public int FollowedBy { get; set; }
12 | }
13 |
14 | public class InstagramData
15 | {
16 | public string Id { get; set; }
17 | public string Username { get; set; }
18 | [JsonProperty("profile_picture")]
19 | public string ProfilePicture { get; set; }
20 | [JsonProperty("full_name")]
21 | public string FullName { get; set; }
22 | public string Bio { get; set; }
23 | public string Website { get; set; }
24 | [JsonProperty("is_business")]
25 | public bool IsBusiness { get; set; }
26 | public InstagramCounts Counts { get; set; }
27 | }
28 |
29 | public class InstagramMeta
30 | {
31 | public int Code { get; set; }
32 | }
33 |
34 | public class InstagramUser
35 | {
36 | public InstagramData Data { get; set; }
37 | public InstagramMeta Meta { get; set; }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Properties/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/GoogleService-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CLIENT_ID
6 | 60015114581-8t3d8n4r2s38fvltdqrnf8ip7thqcntu.apps.googleusercontent.com
7 | REVERSED_CLIENT_ID
8 | com.googleusercontent.apps.60015114581-8t3d8n4r2s38fvltdqrnf8ip7thqcntu
9 | API_KEY
10 | AIzaSyAjgaL2JOzTod5IL_XXUWSL3DA16Qbz1lA
11 | GCM_SENDER_ID
12 | 60015114581
13 | PLIST_VERSION
14 | 1
15 | BUNDLE_ID
16 | com.crossgeeks.SocialMediaAuthentication
17 | PROJECT_ID
18 | social-media-authenticat-1ba2a
19 | STORAGE_BUCKET
20 | social-media-authenticat-1ba2a.appspot.com
21 | IS_ADS_ENABLED
22 |
23 | IS_ANALYTICS_ENABLED
24 |
25 | IS_APPINVITE_ENABLED
26 |
27 | IS_GCM_ENABLED
28 |
29 | IS_SIGNIN_ENABLED
30 |
31 | GOOGLE_APP_ID
32 | 1:60015114581:ios:69ad50bf2733bd97af17dc
33 | DATABASE_URL
34 | https://social-media-authenticat-1ba2a.firebaseio.com
35 |
36 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 | using Android.App;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("SocialMediaAuthentication.Android")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("SocialMediaAuthentication.Android")]
14 | [assembly: AssemblyCopyright("Copyright © 2014")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: ComVisible(false)]
18 |
19 | // Version information for an assembly consists of the following four values:
20 | //
21 | // Major Version
22 | // Minor Version
23 | // Build Number
24 | // Revision
25 | //
26 | // You can specify all the values or you can default the Build and Revision Numbers
27 | // by using the '*' as shown below:
28 | // [assembly: AssemblyVersion("1.0.*")]
29 | [assembly: AssemblyVersion("1.0.0.0")]
30 | [assembly: AssemblyFileVersion("1.0.0.0")]
31 |
32 | // Add some common permissions, these can be removed if not needed
33 | [assembly: UsesPermission(Android.Manifest.Permission.Internet)]
34 | [assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
35 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Views/SocialLoginPage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
24 |
27 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SocialMediaAuthentication.iOS")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SocialMediaAuthentication.iOS")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("72bdc44f-c588-44f3-b6df-9aace7daafdd")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/AppDelegate.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | using Foundation;
6 | using Plugin.FacebookClient;
7 | using Plugin.GoogleClient;
8 | using SocialMediaAuthentication.iOS.Services;
9 | using UIKit;
10 |
11 | namespace SocialMediaAuthentication.iOS
12 | {
13 | // The UIApplicationDelegate for the application. This class is responsible for launching the
14 | // User Interface of the application, as well as listening (and optionally responding) to
15 | // application events from iOS.
16 | [Register("AppDelegate")]
17 | public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
18 | {
19 | public override bool FinishedLaunching(UIApplication app, NSDictionary options)
20 | {
21 | global::Xamarin.Forms.Forms.Init();
22 | LoadApplication(new App(new OAuth2Service()));
23 | FacebookClientManager.Initialize(app, options);
24 | GoogleClientManager.Initialize();
25 | return base.FinishedLaunching(app, options);
26 | }
27 |
28 | public override void OnActivated(UIApplication uiApplication)
29 | {
30 | base.OnActivated(uiApplication);
31 | FacebookClientManager.OnActivated();
32 | }
33 |
34 | public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
35 | {
36 | GoogleClientManager.OnOpenUrl(app, url, options);
37 | return FacebookClientManager.OpenUrl(app, url, options);
38 | }
39 |
40 | public override bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
41 | {
42 | return FacebookClientManager.OpenUrl(application, url, sourceApplication, annotation);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/Views/HomePage.xaml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "60015114581",
4 | "firebase_url": "https://social-media-authenticat-1ba2a.firebaseio.com",
5 | "project_id": "social-media-authenticat-1ba2a",
6 | "storage_bucket": "social-media-authenticat-1ba2a.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:60015114581:android:a881e9a7375530afaf17dc",
12 | "android_client_info": {
13 | "package_name": "com.crossgeeks.socialmediaauthentication"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "60015114581-5iddc0evthbbkgl1v4kq89a25pjkmm7k.apps.googleusercontent.com",
19 | "client_type": 1,
20 | "android_info": {
21 | "package_name": "com.crossgeeks.socialmediaauthentication",
22 | "certificate_hash": "41efd64dbc35e0013a82f7ae57af00af42651d85"
23 | }
24 | },
25 | {
26 | "client_id": "60015114581-nj9q2ekimf9paie9ig0cliulo9vj8mfk.apps.googleusercontent.com",
27 | "client_type": 3
28 | }
29 | ],
30 | "api_key": [
31 | {
32 | "current_key": "AIzaSyBBWJqcO9flWTi90zlrq9pJOUfa2RO_mC4"
33 | }
34 | ],
35 | "services": {
36 | "appinvite_service": {
37 | "other_platform_oauth_client": [
38 | {
39 | "client_id": "60015114581-nj9q2ekimf9paie9ig0cliulo9vj8mfk.apps.googleusercontent.com",
40 | "client_type": 3
41 | },
42 | {
43 | "client_id": "60015114581-8t3d8n4r2s38fvltdqrnf8ip7thqcntu.apps.googleusercontent.com",
44 | "client_type": 2,
45 | "ios_info": {
46 | "bundle_id": "com.crossgeeks.SocialMediaAuthentication"
47 | }
48 | }
49 | ]
50 | }
51 | }
52 | }
53 | ],
54 | "configuration_version": "1"
55 | }
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Resources/AboutResources.txt:
--------------------------------------------------------------------------------
1 | Images, layout descriptions, binary blobs and string dictionaries can be included
2 | in your application as resource files. Various Android APIs are designed to
3 | operate on the resource IDs instead of dealing with images, strings or binary blobs
4 | directly.
5 |
6 | For example, a sample Android app that contains a user interface layout (main.xml),
7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8 | would keep its resources in the "Resources" directory of the application:
9 |
10 | Resources/
11 | drawable-hdpi/
12 | icon.png
13 |
14 | drawable-ldpi/
15 | icon.png
16 |
17 | drawable-mdpi/
18 | icon.png
19 |
20 | layout/
21 | main.xml
22 |
23 | values/
24 | strings.xml
25 |
26 | In order to get the build system to recognize Android resources, set the build action to
27 | "AndroidResource". The native Android APIs do not operate directly with filenames, but
28 | instead operate on resource IDs. When you compile an Android application that uses resources,
29 | the build system will package the resources for distribution and generate a class called
30 | "Resource" that contains the tokens for each one of the resources included. For example,
31 | for the above Resources layout, this is what the Resource class would expose:
32 |
33 | public class Resource {
34 | public class drawable {
35 | public const int icon = 0x123;
36 | }
37 |
38 | public class layout {
39 | public const int main = 0x456;
40 | }
41 |
42 | public class strings {
43 | public const int first_string = 0xabc;
44 | public const int second_string = 0xbcd;
45 | }
46 | }
47 |
48 | You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main
49 | to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
50 | string in the dictionary file values/strings.xml.
51 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Resources/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images": [
3 | {
4 | "scale": "2x",
5 | "size": "20x20",
6 | "idiom": "iphone",
7 | "filename": "Icon40.png"
8 | },
9 | {
10 | "scale": "3x",
11 | "size": "20x20",
12 | "idiom": "iphone",
13 | "filename": "Icon60.png"
14 | },
15 | {
16 | "scale": "2x",
17 | "size": "29x29",
18 | "idiom": "iphone",
19 | "filename": "Icon58.png"
20 | },
21 | {
22 | "scale": "3x",
23 | "size": "29x29",
24 | "idiom": "iphone",
25 | "filename": "Icon87.png"
26 | },
27 | {
28 | "scale": "2x",
29 | "size": "40x40",
30 | "idiom": "iphone",
31 | "filename": "Icon80.png"
32 | },
33 | {
34 | "scale": "3x",
35 | "size": "40x40",
36 | "idiom": "iphone",
37 | "filename": "Icon120.png"
38 | },
39 | {
40 | "scale": "2x",
41 | "size": "60x60",
42 | "idiom": "iphone",
43 | "filename": "Icon120.png"
44 | },
45 | {
46 | "scale": "3x",
47 | "size": "60x60",
48 | "idiom": "iphone",
49 | "filename": "Icon180.png"
50 | },
51 | {
52 | "scale": "1x",
53 | "size": "20x20",
54 | "idiom": "ipad",
55 | "filename": "Icon20.png"
56 | },
57 | {
58 | "scale": "2x",
59 | "size": "20x20",
60 | "idiom": "ipad",
61 | "filename": "Icon40.png"
62 | },
63 | {
64 | "scale": "1x",
65 | "size": "29x29",
66 | "idiom": "ipad",
67 | "filename": "Icon29.png"
68 | },
69 | {
70 | "scale": "2x",
71 | "size": "29x29",
72 | "idiom": "ipad",
73 | "filename": "Icon58.png"
74 | },
75 | {
76 | "scale": "1x",
77 | "size": "40x40",
78 | "idiom": "ipad",
79 | "filename": "Icon40.png"
80 | },
81 | {
82 | "scale": "2x",
83 | "size": "40x40",
84 | "idiom": "ipad",
85 | "filename": "Icon80.png"
86 | },
87 | {
88 | "scale": "1x",
89 | "size": "76x76",
90 | "idiom": "ipad",
91 | "filename": "Icon76.png"
92 | },
93 | {
94 | "scale": "2x",
95 | "size": "76x76",
96 | "idiom": "ipad",
97 | "filename": "Icon152.png"
98 | },
99 | {
100 | "scale": "2x",
101 | "size": "83.5x83.5",
102 | "idiom": "ipad",
103 | "filename": "Icon167.png"
104 | },
105 | {
106 | "scale": "1x",
107 | "size": "1024x1024",
108 | "idiom": "ios-marketing",
109 | "filename": "Icon1024.png"
110 | }
111 | ],
112 | "properties": {},
113 | "info": {
114 | "version": 1,
115 | "author": "xcode"
116 | }
117 | }
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/MainActivity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Android.App;
4 | using Android.Content.PM;
5 | using Android.Runtime;
6 | using Android.Views;
7 | using Android.Widget;
8 | using Android.OS;
9 | using Plugin.FacebookClient;
10 | using Android.Content;
11 | using Java.Security;
12 | using System.Buffers.Text;
13 | using Acr.UserDialogs;
14 | using SocialMediaAuthentication.Droid.Services;
15 | using Plugin.GoogleClient;
16 |
17 | namespace SocialMediaAuthentication.Droid
18 | {
19 | [Activity(Label = "SocialMediaAuthentication", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
20 | public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
21 | {
22 | protected override void OnCreate(Bundle savedInstanceState)
23 | {
24 | TabLayoutResource = Resource.Layout.Tabbar;
25 | ToolbarResource = Resource.Layout.Toolbar;
26 |
27 | base.OnCreate(savedInstanceState);
28 |
29 |
30 | Xamarin.Essentials.Platform.Init(this, savedInstanceState);
31 | global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
32 | FacebookClientManager.Initialize(this);
33 | GoogleClientManager.Initialize(this);
34 | UserDialogs.Init(() => this);
35 | LoadApplication(new App(new OAuth2Service()));
36 | #if DEBUG
37 | PrintHashKey(this);
38 | #endif
39 | }
40 |
41 |
42 | public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
43 | {
44 | Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
45 |
46 | base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
47 | }
48 |
49 | protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent)
50 | {
51 | base.OnActivityResult(requestCode, resultCode, intent);
52 | FacebookClientManager.OnActivityResult(requestCode, resultCode, intent);
53 | GoogleClientManager.OnAuthCompleted(requestCode, resultCode, intent);
54 | }
55 |
56 | public static void PrintHashKey(Context pContext)
57 | {
58 | try
59 | {
60 | PackageInfo info = Android.App.Application.Context.PackageManager.GetPackageInfo(Android.App.Application.Context.PackageName, PackageInfoFlags.Signatures);
61 | foreach (var signature in info.Signatures)
62 | {
63 | MessageDigest md = MessageDigest.GetInstance("SHA");
64 | md.Update(signature.ToByteArray());
65 |
66 | System.Diagnostics.Debug.WriteLine(Convert.ToBase64String(md.Digest()));
67 | }
68 | }
69 | catch (NoSuchAlgorithmException e)
70 | {
71 | System.Diagnostics.Debug.WriteLine(e);
72 | }
73 | catch (Exception e)
74 | {
75 | System.Diagnostics.Debug.WriteLine(e);
76 | }
77 | }
78 | }
79 | }
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Services/OAuth2Service.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using SocialMediaAuthentication.Services;
4 | using UIKit;
5 | using Xamarin.Auth;
6 |
7 | namespace SocialMediaAuthentication.iOS.Services
8 | {
9 | public class iOSOAuth2Authenticator : OAuth2Authenticator
10 | {
11 | public iOSOAuth2Authenticator(string clientId, string scope, Uri authorizeUrl, Uri redirectUrl) : base(clientId, scope, authorizeUrl, redirectUrl)
12 | {
13 |
14 | }
15 |
16 | protected override void OnPageEncountered(Uri url, IDictionary query, IDictionary fragment)
17 | {
18 | if (UrlMatchesRedirect(url))
19 |
20 | base.OnPageEncountered(url, query, fragment);
21 | }
22 |
23 | }
24 |
25 | public class OAuth2Service : IOAuth2Service
26 | {
27 | public event EventHandler OnSuccess = delegate { };
28 | public event EventHandler OnCancel = delegate { };
29 | public event EventHandler OnError = delegate { };
30 |
31 | public void Authenticate(string clientId, string scope, Uri authorizeUrl, Uri redirectUrl)
32 | {
33 |
34 | var window = UIApplication.SharedApplication.KeyWindow;
35 | var vc = window.RootViewController;
36 | while (vc.PresentedViewController != null)
37 | {
38 | vc = vc.PresentedViewController;
39 | }
40 |
41 | var auth = new iOSOAuth2Authenticator(
42 | clientId: clientId, // your OAuth2 client id
43 | scope: scope, // the scopes for the particular API you're accessing, delimited by "+" symbols
44 | authorizeUrl: authorizeUrl, // the auth URL for the service
45 | redirectUrl: redirectUrl); // the redirect URL for the service
46 |
47 | auth.AllowCancel = true;
48 | auth.ShowErrors = false;
49 | EventHandler errorDelegate = null;
50 | EventHandler completedDelegate = null;
51 |
52 | errorDelegate = (sender, eventArgs) =>
53 | {
54 | OnError?.Invoke(this, eventArgs.Message);
55 |
56 | auth.Error -= errorDelegate;
57 | auth.Completed -= completedDelegate;
58 | };
59 |
60 | completedDelegate = (sender, eventArgs) => {
61 |
62 |
63 |
64 | // UI presented, so it's up to us to dimiss it on iOS
65 | // dismiss ViewController with UIWebView or SFSafariViewController
66 | vc.DismissViewController(true, null);
67 |
68 |
69 | if (eventArgs.IsAuthenticated)
70 | {
71 |
72 | OnSuccess?.Invoke(this, eventArgs.Account.Properties["access_token"]);
73 |
74 | }
75 | else
76 | {
77 | // The user cancelled
78 |
79 | OnCancel?.Invoke(this, EventArgs.Empty);
80 | }
81 | auth.Error -= errorDelegate;
82 | auth.Completed -= completedDelegate;
83 |
84 | };
85 |
86 | auth.Error += errorDelegate;
87 | auth.Completed += completedDelegate;
88 |
89 | vc.PresentViewController(auth.GetUI(), true, null);
90 | }
91 |
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | UIDeviceFamily
6 |
7 | 1
8 | 2
9 |
10 | NSAppTransportSecurity
11 |
12 | NSExceptionDomains
13 |
14 | facebook.com
15 |
16 | NSIncludesSubdomains
17 |
18 | NSThirdPartyExceptionRequiresForwardSecrecy
19 |
20 |
21 | fbcdn.net
22 |
23 | NSIncludesSubdomains
24 |
25 | NSThirdPartyExceptionRequiresForwardSecrecy
26 |
27 |
28 | akamaihd.net
29 |
30 | NSIncludesSubdomains
31 |
32 | NSThirdPartyExceptionRequiresForwardSecrecy
33 |
34 |
35 |
36 | NSAllowsArbitraryLoadsInWebContent
37 |
38 |
39 | otherExternalDomainYouNeedToCall
40 |
41 | NSIncludesSubdomains
42 |
43 | NSExceptionAllowsInsecureHTTPLoads
44 |
45 | NSAllowsArbitraryLoads
46 |
47 |
48 | CFBundleURLTypes
49 |
50 |
51 | CFBundleURLName
52 | fb
53 | CFBundleURLSchemes
54 |
55 | fb1212486175604889
56 |
57 |
58 |
59 | CFBundleURLName
60 | google
61 | CFBundleURLSchemes
62 |
63 | com.googleusercontent.apps.60015114581-8t3d8n4r2s38fvltdqrnf8ip7thqcntu
64 |
65 | CFBundleTypeRole
66 | Editor
67 |
68 |
69 | FacebookAppID
70 | 1212486175604889
71 | FacebookDisplayName
72 | SocialMediaAuthentication
73 | LSApplicationQueriesSchemes
74 |
75 | fbapi
76 | fb-messenger-api
77 | fbauth2
78 | fbshareextension
79 |
80 | UISupportedInterfaceOrientations
81 |
82 | UIInterfaceOrientationPortrait
83 | UIInterfaceOrientationLandscapeLeft
84 | UIInterfaceOrientationLandscapeRight
85 |
86 | UISupportedInterfaceOrientations~ipad
87 |
88 | UIInterfaceOrientationPortrait
89 | UIInterfaceOrientationPortraitUpsideDown
90 | UIInterfaceOrientationLandscapeLeft
91 | UIInterfaceOrientationLandscapeRight
92 |
93 | MinimumOSVersion
94 | 12.1
95 | CFBundleDisplayName
96 | SocialMediaAuthentication
97 | CFBundleIdentifier
98 | com.crossgeeks.SocialMediaAuthentication
99 | CFBundleVersion
100 | 1.0
101 | UILaunchStoryboardName
102 | LaunchScreen
103 | CFBundleName
104 | SocialMediaAuthentication
105 | XSAppIconAssets
106 | Assets.xcassets/AppIcon.appiconset
107 |
108 |
109 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/Services/OAuth2Service.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Plugin.CurrentActivity;
3 | using SocialMediaAuthentication.Services;
4 | using Xamarin.Auth;
5 |
6 | namespace SocialMediaAuthentication.Droid.Services
7 | {
8 | public class DroidOAuth2Authenticator : OAuth2Authenticator
9 | {
10 | public DroidOAuth2Authenticator(string clientId, string scope, Uri authorizeUrl, Uri redirectUrl) : base(clientId, scope, authorizeUrl, redirectUrl)
11 | {
12 |
13 | }
14 |
15 | protected override void OnPageEncountered(Uri url, System.Collections.Generic.IDictionary query, System.Collections.Generic.IDictionary fragment)
16 | {
17 | // Remove state from dictionaries.
18 | // We are ignoring request state forgery status
19 | // as we're hitting an ASP.NET service which forwards
20 | // to a third-party OAuth service itself
21 | if (query.ContainsKey("state"))
22 | {
23 | query.Remove("state");
24 | }
25 |
26 | if (fragment.ContainsKey("state"))
27 | {
28 | fragment.Remove("state");
29 | }
30 |
31 | base.OnPageEncountered(url, query, fragment);
32 | }
33 | }
34 |
35 | public class OAuth2Service: IOAuth2Service
36 | {
37 | public event EventHandler OnSuccess = delegate { };
38 | public event EventHandler OnCancel = delegate { };
39 | public event EventHandler OnError = delegate { };
40 |
41 | public void Authenticate(string clientId, string scope, Uri authorizeUrl, Uri redirectUrl)
42 | {
43 | var activity = CrossCurrentActivity.Current.Activity;
44 |
45 | var auth = new DroidOAuth2Authenticator(
46 | clientId: clientId, // your OAuth2 client id
47 | scope: scope, // the scopes for the particular API you're accessing, delimited by "+" symbols
48 | authorizeUrl: authorizeUrl, // the auth URL for the service
49 | redirectUrl: redirectUrl); // the redirect URL for the service
50 |
51 | auth.AllowCancel = true;
52 | auth.ShowErrors = false;
53 |
54 | EventHandler errorDelegate = null;
55 | EventHandler completedDelegate = null;
56 |
57 | errorDelegate = (sender, eventArgs) =>
58 | {
59 | OnError?.Invoke(this, eventArgs.Message);
60 |
61 | auth.Error -= errorDelegate;
62 | auth.Completed -= completedDelegate;
63 | };
64 |
65 | completedDelegate = (sender, eventArgs) => {
66 |
67 | // UI presented, so it's up to us to dimiss it on Android
68 | // dismiss Activity with WebView or CustomTabs
69 | CrossCurrentActivity.Current.Activity.Finish();
70 |
71 | if (eventArgs.IsAuthenticated)
72 | {
73 |
74 | OnSuccess?.Invoke(this, eventArgs.Account.Properties["access_token"]);
75 |
76 | }
77 | else
78 | {
79 | // The user cancelled
80 |
81 | OnCancel?.Invoke(this, EventArgs.Empty);
82 | }
83 | auth.Error -= errorDelegate;
84 | auth.Completed -= completedDelegate;
85 |
86 | };
87 |
88 | auth.Error += errorDelegate;
89 | auth.Completed += completedDelegate;
90 |
91 | activity.StartActivity(auth.GetUI(activity));
92 | }
93 |
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocialMediaAuthentication.Android", "SocialMediaAuthentication.Android\SocialMediaAuthentication.Android.csproj", "{FE607A82-B2D3-48DE-877D-380162257B62}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocialMediaAuthentication.iOS", "SocialMediaAuthentication.iOS\SocialMediaAuthentication.iOS.csproj", "{EF972121-CE18-474B-96B5-F4A7CA4C9024}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocialMediaAuthentication", "SocialMediaAuthentication\SocialMediaAuthentication.csproj", "{EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | Debug|iPhoneSimulator = Debug|iPhoneSimulator
15 | Release|iPhoneSimulator = Release|iPhoneSimulator
16 | Debug|iPhone = Debug|iPhone
17 | Release|iPhone = Release|iPhone
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {FE607A82-B2D3-48DE-877D-380162257B62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {FE607A82-B2D3-48DE-877D-380162257B62}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {FE607A82-B2D3-48DE-877D-380162257B62}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {FE607A82-B2D3-48DE-877D-380162257B62}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {FE607A82-B2D3-48DE-877D-380162257B62}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
25 | {FE607A82-B2D3-48DE-877D-380162257B62}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
26 | {FE607A82-B2D3-48DE-877D-380162257B62}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
27 | {FE607A82-B2D3-48DE-877D-380162257B62}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
28 | {FE607A82-B2D3-48DE-877D-380162257B62}.Debug|iPhone.ActiveCfg = Debug|Any CPU
29 | {FE607A82-B2D3-48DE-877D-380162257B62}.Debug|iPhone.Build.0 = Debug|Any CPU
30 | {FE607A82-B2D3-48DE-877D-380162257B62}.Release|iPhone.ActiveCfg = Release|Any CPU
31 | {FE607A82-B2D3-48DE-877D-380162257B62}.Release|iPhone.Build.0 = Release|Any CPU
32 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator
33 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator
34 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Release|Any CPU.ActiveCfg = Release|iPhoneSimulator
35 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Release|Any CPU.Build.0 = Release|iPhoneSimulator
36 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
37 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
38 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
39 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
40 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Debug|iPhone.ActiveCfg = Debug|iPhone
41 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Debug|iPhone.Build.0 = Debug|iPhone
42 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Release|iPhone.ActiveCfg = Release|iPhone
43 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}.Release|iPhone.Build.0 = Release|iPhone
44 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
49 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
50 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
51 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
52 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Debug|iPhone.ActiveCfg = Debug|Any CPU
53 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Debug|iPhone.Build.0 = Debug|Any CPU
54 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Release|iPhone.ActiveCfg = Release|Any CPU
55 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}.Release|iPhone.Build.0 = Release|Any CPU
56 | EndGlobalSection
57 | EndGlobal
58 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.Android/SocialMediaAuthentication.Android.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {FE607A82-B2D3-48DE-877D-380162257B62}
7 | {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
8 | {c9e5eea5-ca05-42a1-839b-61506e0a37df}
9 | Library
10 | SocialMediaAuthentication.Droid
11 | SocialMediaAuthentication.Android
12 | True
13 | Resources\Resource.designer.cs
14 | Resource
15 | Properties\AndroidManifest.xml
16 | Resources
17 | Assets
18 | v9.0
19 | true
20 | Xamarin.Android.Net.AndroidClientHandler
21 |
22 |
23 |
24 |
25 | true
26 | portable
27 | false
28 | bin\Debug
29 | DEBUG;
30 | prompt
31 | 4
32 | None
33 | d8
34 | r8
35 |
36 |
37 | true
38 | portable
39 | true
40 | bin\Release
41 | prompt
42 | 4
43 | true
44 | false
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | 5.0.3
67 |
68 |
69 | 5.0.3
70 |
71 |
72 | 1.7.0
73 |
74 |
75 | 2.1.0.4
76 |
77 |
78 | 2.1.14
79 |
80 |
81 | 1.1.1
82 |
83 |
84 | 71.1600.0
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}
144 | SocialMediaAuthentication
145 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication.iOS/SocialMediaAuthentication.iOS.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | iPhoneSimulator
6 | 8.0.30703
7 | 2.0
8 | {EF972121-CE18-474B-96B5-F4A7CA4C9024}
9 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
10 | {6143fdea-f3c2-4a09-aafa-6e230626515e}
11 | Exe
12 | SocialMediaAuthentication.iOS
13 | Resources
14 | SocialMediaAuthentication.iOS
15 | true
16 | NSUrlSessionHandler
17 |
18 |
19 | true
20 | full
21 | false
22 | bin\iPhoneSimulator\Debug
23 | DEBUG
24 | prompt
25 | 4
26 | false
27 | x86_64
28 | None
29 | true
30 | iPhone Developer
31 | Entitlements.plist
32 |
33 |
34 | none
35 | true
36 | bin\iPhoneSimulator\Release
37 | prompt
38 | 4
39 | None
40 | x86_64
41 | false
42 |
43 |
44 | true
45 | full
46 | false
47 | bin\iPhone\Debug
48 | DEBUG
49 | prompt
50 | 4
51 | false
52 | ARM64
53 | iPhone Developer
54 | true
55 | Entitlements.plist
56 |
57 |
58 | none
59 | true
60 | bin\iPhone\Release
61 | prompt
62 | 4
63 | ARM64
64 | false
65 | iPhone Developer
66 | Entitlements.plist
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | false
80 |
81 |
82 | false
83 |
84 |
85 | false
86 |
87 |
88 | false
89 |
90 |
91 | false
92 |
93 |
94 | false
95 |
96 |
97 | false
98 |
99 |
100 | false
101 |
102 |
103 | false
104 |
105 |
106 | false
107 |
108 |
109 | false
110 |
111 |
112 | false
113 |
114 |
115 | false
116 |
117 |
118 | false
119 |
120 |
121 | False
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 | 1.7.0
140 |
141 |
142 | 2.1.14
143 |
144 |
145 | 1.1.1
146 |
147 |
148 | 4.4.0
149 |
150 |
151 |
152 |
153 |
154 | {EA86E5F8-7B20-4EEA-A21D-A7E1C1FF7404}
155 | SocialMediaAuthentication
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
--------------------------------------------------------------------------------
/SocialMediaAuthentication/ViewModels/SocialLoginPageViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.ObjectModel;
3 | using System.Diagnostics;
4 | using System.Threading.Tasks;
5 | using System.Windows.Input;
6 | using Acr.UserDialogs;
7 | using Newtonsoft.Json;
8 | using Plugin.FacebookClient;
9 | using Plugin.GoogleClient;
10 | using Plugin.GoogleClient.Shared;
11 | using Refit;
12 | using SocialMediaAuthentication.Models;
13 | using SocialMediaAuthentication.Services;
14 | using SocialMediaAuthentication.Views;
15 | using Xamarin.Forms;
16 |
17 | namespace SocialMediaAuthentication.ViewModels
18 | {
19 | public class SocialLoginPageViewModel
20 | {
21 | const string InstagramApiUrl = "https://api.instagram.com";
22 | const string InstagramScope = "basic";
23 | const string InstagramAuthorizationUrl = "https://api.instagram.com/oauth/authorize/";
24 | const string InstagramRedirectUrl = "https://xamboy.com/default.html";
25 | const string InstagramClientId = "77567512de424a528ba61715d389a644";
26 |
27 | public ICommand OnLoginCommand { get; set; }
28 |
29 | IFacebookClient _facebookService = CrossFacebookClient.Current;
30 | IGoogleClientManager _googleService = CrossGoogleClient.Current;
31 | IOAuth2Service _oAuth2Service;
32 |
33 |
34 | public ObservableCollection AuthenticationNetworks { get; set; } = new ObservableCollection()
35 | {
36 | new AuthNetwork()
37 | {
38 | Name = "Facebook",
39 | Icon = "ic_fb",
40 | Foreground = "#FFFFFF",
41 | Background = "#4768AD"
42 | },
43 | new AuthNetwork()
44 | {
45 | Name = "Instagram",
46 | Icon = "ic_ig",
47 | Foreground = "#FFFFFF",
48 | Background = "#DD2A7B"
49 | },
50 | new AuthNetwork()
51 | {
52 | Name = "Google",
53 | Icon = "ic_google",
54 | Foreground = "#000000",
55 | Background ="#F8F8F8"
56 | }
57 | };
58 |
59 |
60 | public SocialLoginPageViewModel(IOAuth2Service oAuth2Service)
61 | {
62 | _oAuth2Service = oAuth2Service;
63 |
64 | OnLoginCommand = new Command(async (data) => await LoginAsync(data));
65 | }
66 | async Task LoginAsync(AuthNetwork authNetwork)
67 | {
68 | switch(authNetwork.Name)
69 | {
70 | case "Facebook":
71 | await LoginFacebookAsync(authNetwork);
72 | break;
73 | case "Instagram":
74 | await LoginInstagramAsync(authNetwork);
75 | break;
76 | case "Google":
77 | await LoginGoogleAsync(authNetwork);
78 | break;
79 | }
80 | }
81 | async Task LoginInstagramAsync(AuthNetwork authNetwork)
82 | {
83 | EventHandler onSuccessDelegate = null;
84 | EventHandler onErrorDelegate = null;
85 | EventHandler onCancelDelegate = null;
86 |
87 | onSuccessDelegate = async (s, a) =>
88 | {
89 |
90 | UserDialogs.Instance.ShowLoading("Loading");
91 |
92 | var userResponse = await RestService.For(InstagramApiUrl).GetUser(a);
93 |
94 | if (userResponse.IsSuccessStatusCode)
95 | {
96 | var userDataString = await userResponse.Content.ReadAsStringAsync();
97 | //Handling Encoding
98 | var userDataStringFixed = System.Text.RegularExpressions.Regex.Unescape(userDataString);
99 |
100 | var instagramUser = JsonConvert.DeserializeObject(userDataStringFixed);
101 | var socialLoginData = new NetworkAuthData
102 | {
103 | Logo = authNetwork.Icon,
104 | Picture = instagramUser.Data.ProfilePicture,
105 | Foreground = authNetwork.Foreground,
106 | Background = authNetwork.Background,
107 | Name = instagramUser.Data.FullName,
108 | Id = instagramUser.Data.Id
109 | };
110 |
111 | UserDialogs.Instance.HideLoading();
112 | await App.Current.MainPage.Navigation.PushModalAsync(new HomePage(socialLoginData));
113 | }
114 | else
115 | {
116 | //TODO: Handle instagram user info error
117 | UserDialogs.Instance.HideLoading();
118 |
119 | await UserDialogs.Instance.AlertAsync("Error","Houston we have a problem" , "Ok");
120 | }
121 |
122 | _oAuth2Service.OnSuccess -= onSuccessDelegate;
123 | _oAuth2Service.OnCancel -= onCancelDelegate;
124 | _oAuth2Service.OnError -= onErrorDelegate;
125 | };
126 | onErrorDelegate = (s, a) =>
127 | {
128 | _oAuth2Service.OnSuccess -= onSuccessDelegate;
129 | _oAuth2Service.OnCancel -= onCancelDelegate;
130 | _oAuth2Service.OnError -= onErrorDelegate;
131 | Debug.WriteLine($"ERROR: Instagram, MESSAGE: {a}");
132 | };
133 | onCancelDelegate = (s, a) =>
134 | {
135 | _oAuth2Service.OnSuccess -= onSuccessDelegate;
136 | _oAuth2Service.OnCancel -= onCancelDelegate;
137 | _oAuth2Service.OnError -= onErrorDelegate;
138 | };
139 |
140 | _oAuth2Service.OnSuccess += onSuccessDelegate;
141 | _oAuth2Service.OnCancel += onCancelDelegate;
142 | _oAuth2Service.OnError += onErrorDelegate;
143 | _oAuth2Service.Authenticate(InstagramClientId, InstagramScope, new Uri(InstagramAuthorizationUrl), new Uri(InstagramRedirectUrl));
144 |
145 |
146 | }
147 |
148 | async Task LoginFacebookAsync(AuthNetwork authNetwork)
149 | {
150 | try
151 | {
152 |
153 | if (_facebookService.IsLoggedIn)
154 | {
155 | _facebookService.Logout();
156 | }
157 |
158 | EventHandler> userDataDelegate = null;
159 |
160 | userDataDelegate = async (object sender, FBEventArgs e) =>
161 | {
162 | switch (e.Status)
163 | {
164 | case FacebookActionStatus.Completed:
165 | var facebookProfile = await Task.Run(() => JsonConvert.DeserializeObject(e.Data));
166 | var socialLoginData = new NetworkAuthData
167 | {
168 | Id = facebookProfile.Id,
169 | Logo = authNetwork.Icon,
170 | Foreground = authNetwork.Foreground,
171 | Background = authNetwork.Background,
172 | Picture = facebookProfile.Picture.Data.Url,
173 | Name = $"{facebookProfile.FirstName} {facebookProfile.LastName}",
174 | };
175 | await App.Current.MainPage.Navigation.PushModalAsync(new HomePage(socialLoginData));
176 | break;
177 | case FacebookActionStatus.Canceled:
178 | await App.Current.MainPage.DisplayAlert("Facebook Auth", "Canceled", "Ok");
179 | break;
180 | case FacebookActionStatus.Error:
181 | await App.Current.MainPage.DisplayAlert("Facebook Auth", "Error", "Ok");
182 | break;
183 | case FacebookActionStatus.Unauthorized:
184 | await App.Current.MainPage.DisplayAlert("Facebook Auth", "Unauthorized", "Ok");
185 | break;
186 | }
187 |
188 | _facebookService.OnUserData -= userDataDelegate;
189 | };
190 |
191 | _facebookService.OnUserData += userDataDelegate;
192 |
193 | string[] fbRequestFields = { "email", "first_name", "picture", "gender", "last_name" };
194 | string[] fbPermisions = { "email" };
195 | await _facebookService.RequestUserDataAsync(fbRequestFields, fbPermisions);
196 | }
197 | catch (Exception ex)
198 | {
199 | Debug.WriteLine(ex.ToString());
200 | }
201 | }
202 |
203 | async Task LoginGoogleAsync(AuthNetwork authNetwork)
204 | {
205 | try
206 | {
207 | if (!string.IsNullOrEmpty(_googleService.ActiveToken))
208 | {
209 | //Always require user authentication
210 | _googleService.Logout();
211 | }
212 |
213 | EventHandler> userLoginDelegate = null;
214 | userLoginDelegate = async (object sender, GoogleClientResultEventArgs e) =>
215 | {
216 | switch (e.Status)
217 | {
218 | case GoogleActionStatus.Completed:
219 | #if DEBUG
220 | var googleUserString = JsonConvert.SerializeObject(e.Data);
221 | Debug.WriteLine($"Google Logged in succesfully: {googleUserString}");
222 | #endif
223 |
224 | var socialLoginData = new NetworkAuthData
225 | {
226 | Id = e.Data.Id,
227 | Logo = authNetwork.Icon,
228 | Foreground = authNetwork.Foreground,
229 | Background = authNetwork.Background,
230 | Picture = e.Data.Picture.AbsoluteUri,
231 | Name = e.Data.Name,
232 | };
233 |
234 | await App.Current.MainPage.Navigation.PushModalAsync(new HomePage(socialLoginData));
235 | break;
236 | case GoogleActionStatus.Canceled:
237 | await App.Current.MainPage.DisplayAlert("Google Auth", "Canceled", "Ok");
238 | break;
239 | case GoogleActionStatus.Error:
240 | await App.Current.MainPage.DisplayAlert("Google Auth", "Error", "Ok");
241 | break;
242 | case GoogleActionStatus.Unauthorized:
243 | await App.Current.MainPage.DisplayAlert("Google Auth", "Unauthorized", "Ok");
244 | break;
245 | }
246 |
247 | _googleService.OnLogin -= userLoginDelegate;
248 | };
249 |
250 | _googleService.OnLogin += userLoginDelegate;
251 |
252 | await _googleService.LoginAsync();
253 | }
254 | catch (Exception ex)
255 | {
256 | Debug.WriteLine(ex.ToString());
257 | }
258 | }
259 |
260 | }
261 | }
262 |
--------------------------------------------------------------------------------