public static OAuthBase CreateProvider(SNSProvider provider) { switch (provider) { case SNSProvider.Facebook: return(FacebookOAuth.Instance); } return(null); }
public async void OAuthLoginAsync(SNSProvider provider) { try { if (!ApiService.CheckInternetConnected()) { await UserDialogs.Instance.AlertAsync("Please check internet connection"); } var oAuth = OAuthProviderFactory.CreateProvider(provider); var authenticator = new OAuth2Authenticator( oAuth.ClientId, oAuth.Scope, new Uri(oAuth.AuthorizationUrl), new Uri(oAuth.RedirectUrl)); // Completed authenticator.Completed += async(sender, eventArgs) => { _isAuthenticated = eventArgs.IsAuthenticated; if (IsAuthenticated) { string token = eventArgs.Account.Properties["access_token"]; _authenticatedUser = await oAuth.GetUserInfoAsync(token); LocalStorage.Storage.AddOrUpdateValue(StorageKey.ExternAuthUserInfo, _authenticatedUser); Singleton.Get <ViewLocator>().Login.PoseLoginAsync(); } }; // Error authenticator.Error += async(sender, eventArgs) => { _isAuthenticated = false; await UserDialogs.Instance.AlertAsync($"Authentication error: {eventArgs.Message}"); }; var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter(); presenter.Login(authenticator); // 로그인 폼 닫힘 presenter.Completed += (sender, eventArgs) => { UserDialogs.Instance.HideLoading(); }; } catch (Exception ex) { Debug.WriteLine("Login Error : " + ex.Message); } }
public static OAuth2Base CreateProvider(SNSProvider provider) { OAuth2Base oAuth2 = null; switch (provider) { case SNSProvider.Kakao: oAuth2 = KakaoOAuth2.Instance; break; } return(oAuth2); }
public bool LoginWithSNS(SNSProvider provider) { try { oAuth2 = OAuth2ProviderFactory.CreateProvider(provider); var authenticator = new OAuth2Authenticator( oAuth2.ClientId, oAuth2.ClientSecret, oAuth2.Scope, oAuth2.AuthorizationUri, oAuth2.RedirectUri, oAuth2.RequestTokenUri, null, oAuth2.IsUsingNativeUI); authenticator.Completed += async(s, e) => { //var auth2Authenticator = s as OAuth2Authenticator; if (e.IsAuthenticated) { // If the user is authenticated, request their basic user data from Google // UserInfoUrl = https://www.googleapis.com/oauth2/v2/userinfo var user = await oAuth2.GetUserInfoAsync(e.Account); //AppSettings.User = user; user.SaveUserInfo(); MessagingCenter.Send(user, MessengerKeys.AuthenticationRequested, true); //Debug.WriteLine("Authentication Success"); } }; authenticator.Error += (s, e) => { //Debug.WriteLine("Authentication error: " + e.Message); }; var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter(); presenter.Login(authenticator); } catch (Exception ex) { //Debug.WriteLine("Login Error : " + ex.Message); return(false); } return(true); }
public static OAuth2Base CreateProvider(SNSProvider provider) { OAuth2Base oAuth2 = KakaoOAuth2.Instance;; /* * 카카오 이외에 다른 OAuth2 형태의 인증 철차시 사용 * switch (provider) * { * case SNSProvider.Kakao: * oAuth2 = KakaoOAuth2.Instance; * break; * } */ return(oAuth2); }
public Task LoginWithSNSAsync(SNSProvider provider) { try { oAuth2 = OAuth2ProviderFactory.CreateProvider(provider); var authenticator = new OAuth2Authenticator( oAuth2.ClientId, oAuth2.ClientSecret, oAuth2.Scope, oAuth2.AuthorizationUri, oAuth2.RedirectUri, oAuth2.RequestTokenUri, null, oAuth2.IsUsingNativeUI); authenticator.Completed += async(s, e) => { if (e.IsAuthenticated) { var user = await oAuth2.GetUserInfoAsync(e.Account); AppSettings.User = user; MessagingCenter.Send(user, MessengerKey.AuthenticationRequested, true); Debug.WriteLine("Authentication Success"); } }; authenticator.Error += (s, e) => { Debug.WriteLine("Authentication error: " + e.Message); }; var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter(); presenter.Login(authenticator); } catch (Exception ex) { Debug.WriteLine("Login Error : " + ex.Message); return(Task.FromResult(false)); } return(Task.FromResult(true)); }
public static OAuth2Base CreateProvider(SNSProvider provider) { OAuth2Base oAuth2 = null; switch (provider) { case SNSProvider.Kakao: oAuth2 = KakaoOAuth2.Instance; break; case SNSProvider.Line: //oAuth2 = LineOAuth2.Instance; break; case SNSProvider.Facebook: //oAuth2 = FacebookOAuth2.Instance; break; } return(oAuth2); }