public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); if (!IsShown) { IsShown = true; // TODO: polymorfic HolisticWare.Auth.OAuth1 oauth1 = this.OAuth as HolisticWare.Auth.OAuth1; HolisticWare.Auth.OAuth2 oauth2 = this.OAuth as HolisticWare.Auth.OAuth2; if (null != oauth1) { Login(oauth1); return; } if (null != oauth2) { Login(oauth2); return; } throw new ArgumentOutOfRangeException("Unknown OAuth"); /* * */ } return; }
public void Login() { base.UpdateLayout(); if (!IsShown) { IsShown = true; // TODO: polymorfic HolisticWare.Auth.OAuth1 oauth1 = this.OAuth as HolisticWare.Auth.OAuth1; HolisticWare.Auth.OAuth2 oauth2 = this.OAuth as HolisticWare.Auth.OAuth2; if (null != oauth1) { Login(oauth1); return; } if (null != oauth2) { Login(oauth2); return; } throw new ArgumentOutOfRangeException("Unknown OAuth"); /* * */ } return; }
private void Login(HolisticWare.Auth.OAuth2 oauth2) { global::Xamarin.Auth.OAuth2Authenticator auth = null; if ( null == oauth2.OAuth1_UriAccessToken) { try { auth = new global::Xamarin.Auth.OAuth2Authenticator( clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer, scope: oauth2.OAuth2_Scope, authorizeUrl: oauth2.OAuth_UriAuthorization, redirectUrl: oauth2.OAuth_UriCallbackAKARedirect, getUsernameAsync: null ); } catch (System.Exception exc) { throw exc; } } else { try { auth = new global::Xamarin.Auth.OAuth2Authenticator ( clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer, clientSecret: oauth2.OAuth1_SecretKey_ConsumerSecret_APISecret, scope: oauth2.OAuth2_Scope, authorizeUrl: oauth2.OAuth_UriAuthorization, redirectUrl: oauth2.OAuth_UriCallbackAKARedirect, accessTokenUrl: oauth2.OAuth1_UriAccessToken, getUsernameAsync: null ); } catch (System.Exception exc) { throw exc; } } auth.Completed += auth_Completed; Uri uri = auth.GetUI(); var rv = System.Windows.Application.Current.RootVisual; Microsoft.Phone.Controls.PhoneApplicationFrame paf = null; paf = rv as Microsoft.Phone.Controls.PhoneApplicationFrame; paf.Navigate(uri); return; }
partial void SetPublicDemoDataInstagramOAuth2() { oauth2 = new HolisticWare.Auth.OAuth2() { OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer = "", OAuth2_Scope = "basic", OAuth_UriAuthorization = new Uri("https://api.instagram.com/oauth/authorize/"), OAuth_UriCallbackAKARedirect = new Uri("http://xamarin.com"), }; return; }
private void Login(HolisticWare.Auth.OAuth2 oauth2) { global::Xamarin.Auth.OAuth2Authenticator auth = null; if ( null == oauth2.OAuth1_UriAccessToken) { try { auth = new global::Xamarin.Auth.OAuth2Authenticator ( clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer, scope: oauth2.OAuth2_Scope, authorizeUrl: oauth2.OAuth_UriAuthorization, redirectUrl: oauth2.OAuth_UriCallbackAKARedirect, getUsernameAsync: null ); auth.Error += Auth_Error; } catch (System.Exception exc) { throw exc; } } else { try { auth = new global::Xamarin.Auth.OAuth2Authenticator ( clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer, clientSecret: oauth2.OAuth1_SecretKey_ConsumerSecret_APISecret, scope: oauth2.OAuth2_Scope, authorizeUrl: oauth2.OAuth_UriAuthorization, redirectUrl: oauth2.OAuth_UriCallbackAKARedirect, accessTokenUrl: oauth2.OAuth1_UriAccessToken, getUsernameAsync: null ); } catch (System.Exception exc) { throw exc; } } auth.Completed += auth_Completed; activity.StartActivity(auth.GetUI(activity)); return; }
partial void SetPublicDemoDataFacebookOAuth2() { oauth2 = new HolisticWare.Auth.OAuth2() { OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer = "", OAuth2_Scope = "", // "", "basic", "email", OAuth_UriAuthorization = new Uri("https://m.facebook.com/dialog/oauth/"), OAuth_UriCallbackAKARedirect = new Uri("http://xamarin.com"), }; page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); return; }
partial void SetPublicDemoDataGithubOAuth2() { /// https://developer.github.com/v3/oauth/#scopes oauth2 = new HolisticWare.Auth.OAuth2() { OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer = "", OAuth2_Scope = "", // "", "user", OAuth_UriAuthorization = new Uri("https://github.com/login/oauth/authorize"), OAuth_UriCallbackAKARedirect = new Uri("http://xamarin.com"), }; page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); return; }
partial void SetPublicDemoDataMicrosoftLiveOAuth2() { oauth2 = new HolisticWare.Auth.OAuth2() { /* * clientId: "<MyclientI>", * scope: "wl.basic, wl.signin, wl.offline_access", * authorizeUrl: new Uri(""https://login.live.com/oauth20_authorize.srf"), * redirectUrl: new Uri("https://login.live.com/oauth20_desktop.srf")) */ OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer = "", OAuth2_Scope = "wl.basic, wl.signin, wl.offline_access", OAuth_UriAuthorization = new Uri("https://login.live.com/oauth20_authorize.srf"), OAuth_UriCallbackAKARedirect = new Uri("http://xamarin.com"), }; return; }
protected override void OnElementChanged(ElementChangedEventArgs <Page> e) { base.OnElementChanged(e); // OnElementChanged is fired before ViewDidAppear, using it to pass data PageLogin e_new = e.NewElement as PageLogin; this.OAuth = e_new.OAuth; // PageRenderer is a ViewGroup - so should be able to load an AXML file and FindView<> activity = this.Context as Activity; if (!IsShown) { IsShown = true; // TODO: polymorfic HolisticWare.Auth.OAuth1 oauth1 = this.OAuth as HolisticWare.Auth.OAuth1; HolisticWare.Auth.OAuth2 oauth2 = this.OAuth as HolisticWare.Auth.OAuth2; if (null != oauth1) { Login(oauth1); return; } if (null != oauth2) { Login(oauth2); return; } throw new ArgumentOutOfRangeException("Unknown OAuth"); /* * */ } return; return; }
partial void SetPublicDemoDataGoogleOAuth2() { // https://www.snip2code.com/Snippet/245686/Xamarin-Google-and-Facebook-authenticati /* * clientId: "123456789.apps.googleusercontent.com", * scope: "https://www.googleapis.com/auth/userinfo.email", * authorizeUrl: new Uri ("https://accounts.google.com/o/oauth2/auth"), * redirectUrl: new Uri ("http://bunchy.com/oauth2callback"), * getUsernameAsync: null) */ oauth2 = new HolisticWare.Auth.OAuth2() { OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer = "", OAuth2_Scope = "https://www.googleapis.com/auth/userinfo.email", OAuth_UriAuthorization = new Uri("https://accounts.google.com/o/oauth2/auth"), OAuth_UriCallbackAKARedirect = new Uri("http://xamarin.com"), }; page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); return; }
partial void SetPublicDemoDataLinkedInOAuth2() { /* * https://www.linkedin.com/secure/developer * https://developer.linkedin.com/docs/oauth2 * https://developer.linkedin.com/docs/ * https://developer.linkedin.com/docs/signin-with-linkedin * * * http://forums.xamarin.com/discussion/14883/login-with-linkedin * https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=***" * * http://forums.xamarin.com/discussion/25457/xamarin-auth * * TODO: need testing... not quite correct * */ oauth2 = new HolisticWare.Auth.OAuth2() { OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer = "", OAuth2_Scope = "r_basicprofile", OAuth_UriAuthorization = new Uri ( "https://www.linkedin.com/uas/oauth2/authorization?response_type=code" + "&client_id=" + "" + "&scope=" + Uri.EscapeDataString("r_basicprofile") + "&redirect_uri=" + Uri.EscapeDataString("https://xamarin.com/") ), OAuth_UriCallbackAKARedirect = new Uri("https://xamarin.com/"), }; return; }
public void OnItemSelected(object sender, ItemTappedEventArgs args_tapped) { object item = args_tapped.Item; KeyValuePair <string, string> kvp = (KeyValuePair <string, string>)item; string authentication_provider = kvp.Value; oauth1 = null; oauth2 = null; switch (authentication_provider) { case "Google OAuth2": SetPublicDemoDataGoogleOAuth2(); SetSensitiveDataGoogleOAuth2(); page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); break; case "Facebook OAuth2": SetPublicDemoDataFacebookOAuth2(); SetSensitiveDataFacebookOAuth2(); page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); break; case "Twitter OAuth1": SetPublicDemoDataTwitterOAuth1(); SetSensitiveDataTwitterOAuth1(); page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth1); break; case "Microsoft Live OAuth2": SetPublicDemoDataMicrosoftLiveOAuth2(); SetSensitiveDataMicrosoftLiveOAuth2(); page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); break; case "Instagram OAuth2": SetPublicDemoDataInstagramOAuth2(); SetSensitiveDataInstagramOAuth2(); page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); break; /* * case "LinkedIn OAuth1": * SetPublicDemoDataLinkedInOAuth1(); * SetSensitiveDataLinkedInOAuth1(); * * page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth1); * * break; */ case "LinkedIn OAuth2": SetPublicDemoDataLinkedInOAuth2(); SetSensitiveDataLinkedInOAuth2(); page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); break; case "Github OAuth2": SetPublicDemoDataGithubOAuth2(); SetSensitiveDataGithubOAuth2(); page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); break; case "Youtube OAuth2": SetPublicDemoDataYoutubeOAuth2(); SetSensitiveDataYoutubeOAuth2(); page = new HolisticWare.XamarinForms.Authentication.PageLogin(oauth2); break; default: string msg = "Unknown Authentication Provider: " + authentication_provider; throw new NotImplementedException(msg); } this.Navigation.PushAsync(page); return; }