public GitterAuth(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null)
            : this(redirectUrl, clientSecret, accessTokenUrl)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentException("clientId must be provided", "clientId");
            }
            this.clientId = clientId;

            if (string.IsNullOrEmpty(clientSecret))
            {
                throw new ArgumentException("clientSecret must be provided", "clientSecret");
            }
            this.clientSecret = clientSecret;

            this.scope = scope ?? "";

            if (authorizeUrl == null)
            {
                throw new ArgumentNullException("authorizeUrl");
            }
            this.authorizeUrl = authorizeUrl;

            if (accessTokenUrl == null)
            {
                throw new ArgumentNullException("accessTokenUrl");
            }
            this.accessTokenUrl = accessTokenUrl;

            this.getUsernameAsync = getUsernameAsync;
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Xamarin.Auth.OAuth1Authenticator"/> class.
		/// </summary>
		/// <param name='consumerKey'>
		/// Consumer key.
		/// </param>
		/// <param name='consumerSecret'>
		/// Consumer secret.
		/// </param>
		/// <param name='requestTokenUrl'>
		/// Request token URL.
		/// </param>
		/// <param name='authorizeUrl'>
		/// Authorize URL.
		/// </param>
		/// <param name='accessTokenUrl'>
		/// Access token URL.
		/// </param>
		/// <param name='callbackUrl'>
		/// Callback URL.
		/// </param>
		/// <param name='getUsernameAsync'>
		/// Method used to fetch the username of an account
		/// after it has been successfully authenticated.
		/// </param>
		public OAuth1Authenticator (string consumerKey, string consumerSecret, Uri requestTokenUrl, Uri authorizeUrl, Uri accessTokenUrl, Uri callbackUrl, GetUsernameAsyncFunc getUsernameAsync = null)
		{
			if (string.IsNullOrEmpty (consumerKey)) {
				throw new ArgumentException ("consumerKey must be provided", "consumerKey");
			}
			this.consumerKey = consumerKey;

			if (string.IsNullOrEmpty (consumerSecret)) {
				throw new ArgumentException ("consumerSecret must be provided", "consumerSecret");
			}
			this.consumerSecret = consumerSecret;

			if (requestTokenUrl == null) {
				throw new ArgumentNullException ("requestTokenUrl");
			}
			this.requestTokenUrl = requestTokenUrl;

			if (authorizeUrl == null) {
				throw new ArgumentNullException ("authorizeUrl");
			}
			this.authorizeUrl = authorizeUrl;

			if (accessTokenUrl == null) {
				throw new ArgumentNullException ("accessTokenUrl");
			}
			this.accessTokenUrl = accessTokenUrl;

			if (callbackUrl == null) {
				throw new ArgumentNullException ("callbackUrl");
			}
			this.callbackUrl = callbackUrl;

			this.getUsernameAsync = getUsernameAsync;
		}
Ejemplo n.º 3
0
			public DropboxAuthenticator (bool embedded, string consumerKey, string consumerSecret, Uri requestTokenUrl, Uri authorizeUrl, Uri accessTokenUrl, Uri callbackUrl, GetUsernameAsyncFunc getUsernameAsync = null)
				: base (consumerKey, consumerSecret, requestTokenUrl, authorizeUrl, accessTokenUrl, callbackUrl, getUsernameAsync)
			{
				Embedded = embedded;
				Title = "Connect Dropbox";

				this.authorizeUrl = embedded ? new Uri (authorizeUrl, "?embedded=1") : authorizeUrl;
			}
 public GitterAuth(GetUsernameAsyncFunc getUsernameAsync = null)
     : this("a0fc459712567a41ccd5fb8bbfbf35ce0ea6cb56",
     "fbf16dedfed97d1d059604cedaf8bfc2d69d3cbe",
     String.Empty,
     new Uri("https://gitter.im/login/oauth/authorize"),
     new Uri("http://oauth.gitter.flagbug.com"),
     new Uri("https://gitter.im/login/oauth/token"),
     getUsernameAsync)
 { }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Xamarin.Auth.OAuth1Authenticator"/> class.
        /// </summary>
        /// <param name='consumerKey'>
        /// Consumer key.
        /// </param>
        /// <param name='consumerSecret'>
        /// Consumer secret.
        /// </param>
        /// <param name='requestTokenUrl'>
        /// Request token URL.
        /// </param>
        /// <param name='authorizeUrl'>
        /// Authorize URL.
        /// </param>
        /// <param name='accessTokenUrl'>
        /// Access token URL.
        /// </param>
        /// <param name='callbackUrl'>
        /// Callback URL.
        /// </param>
        /// <param name='getUsernameAsync'>
        /// Method used to fetch the username of an account
        /// after it has been successfully authenticated.
        /// </param>
        public OAuth1Authenticator(string consumerKey, string consumerSecret, Uri requestTokenUrl, Uri authorizeUrl, Uri accessTokenUrl, Uri callbackUrl, GetUsernameAsyncFunc getUsernameAsync = null)
        {
            if (string.IsNullOrEmpty(consumerKey))
            {
                throw new ArgumentException("consumerKey must be provided", "consumerKey");
            }
            this.consumerKey = consumerKey;

            if (string.IsNullOrEmpty(consumerSecret))
            {
                throw new ArgumentException("consumerSecret must be provided", "consumerSecret");
            }
            this.consumerSecret = consumerSecret;

            if (requestTokenUrl == null)
            {
                throw new ArgumentNullException("requestTokenUrl");
            }
            this.requestTokenUrl = requestTokenUrl;

            if (authorizeUrl == null)
            {
                throw new ArgumentNullException("authorizeUrl");
            }
            this.authorizeUrl = authorizeUrl;

            if (accessTokenUrl == null)
            {
                throw new ArgumentNullException("accessTokenUrl");
            }
            this.accessTokenUrl = accessTokenUrl;

            if (callbackUrl == null)
            {
                throw new ArgumentNullException("callbackUrl");
            }
            this.callbackUrl = callbackUrl;

            this.getUsernameAsync = getUsernameAsync;

            this.HttpWebClientFrameworkType = Auth.HttpWebClientFrameworkType.WebRequest;
        }
        /// <summary>
        /// Initializes a new <see cref="Xamarin.Auth.OAuth2Authenticator"/>
        /// that authenticates using implicit granting (token).
        /// </summary>
        /// <param name='clientId'>
        /// Client identifier.
        /// </param>
        /// <param name='scope'>
        /// Authorization scope.
        /// </param>
        /// <param name='authorizeUrl'>
        /// Authorize URL.
        /// </param>
        /// <param name='redirectUrl'>
        /// Redirect URL.
        /// </param>
        /// <param name='getUsernameAsync'>
        /// Method used to fetch the username of an account
        /// after it has been successfully authenticated.
        /// </param>
        public OAuth2Authenticator(string clientId, string scope, Uri authorizeUrl, Uri redirectUrl, GetUsernameAsyncFunc getUsernameAsync = null)
            : this(redirectUrl)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentException("clientId must be provided", "clientId");
            }
            this.clientId = clientId;

            this.scope = scope ?? "";

            if (authorizeUrl == null)
            {
                throw new ArgumentNullException("authorizeUrl");
            }
            this.authorizeUrl = authorizeUrl;

            this.getUsernameAsync = getUsernameAsync;

            this.accessTokenUrl = null;
        }
Ejemplo n.º 7
0
        public void TriggerOAuth2Flow(
            string clientId,
            string clientSecret,
            string scope,
            string authorizeUrl,
            string redirectUrl,
            string accessTokenUrl,
            GetUsernameAsyncFunc getUsernameAsync = null,
            bool isUsingNativeUI = true)
        {
            if (string.IsNullOrEmpty(accessTokenUrl))
            {
                AuthenticationState.Authenticator = new OAuth2Authenticator(
                    clientId,
                    scope,
                    new Uri(authorizeUrl),
                    new Uri(redirectUrl),
                    getUsernameAsync: getUsernameAsync,
                    isUsingNativeUI: isUsingNativeUI);
            }
            else
            {
                AuthenticationState.Authenticator = new OAuth2Authenticator(
                    clientId,
                    clientSecret,
                    scope,
                    new Uri(authorizeUrl),
                    new Uri(redirectUrl),
                    new Uri(accessTokenUrl),
                    getUsernameAsync: getUsernameAsync,
                    isUsingNativeUI: isUsingNativeUI);
            }

            _authFlowTriggered.OnNext(Unit.Default);
            var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();

            presenter.Login(AuthenticationState.Authenticator);
        }
Ejemplo n.º 8
0
		/// <summary>
		/// Initializes a new <see cref="Xamarin.Auth.OAuth2Authenticator"/>
		/// that authenticates using implicit granting (token).
		/// </summary>
		/// <param name='clientId'>
		/// Client identifier.
		/// </param>
		/// <param name='scope'>
		/// Authorization scope.
		/// </param>
		/// <param name='authorizeUrl'>
		/// Authorize URL.
		/// </param>
		/// <param name='redirectUrl'>
		/// Redirect URL.
		/// </param>
		/// <param name='getUsernameAsync'>
		/// Method used to fetch the username of an account
		/// after it has been successfully authenticated.
		/// </param>
		public OAuth2Authenticator (string clientId, string scope, Uri authorizeUrl, Uri redirectUrl, GetUsernameAsyncFunc getUsernameAsync = null)
			: this (redirectUrl)
		{
			if (string.IsNullOrEmpty (clientId)) {
				throw new ArgumentException ("clientId must be provided", "clientId");
			}
			this.clientId = clientId;

			this.scope = scope ?? "";

			if (authorizeUrl == null) {
				throw new ArgumentNullException ("authorizeUrl");
			}
			this.authorizeUrl = authorizeUrl;

			if (redirectUrl == null) {
				throw new ArgumentNullException ("redirectUrl");
			}
			this.redirectUrl = redirectUrl;

			this.getUsernameAsync = getUsernameAsync;

			this.accessTokenUrl = null;
		}
Ejemplo n.º 9
0
 public MixRadioAuth(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null)
     : base(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, getUsernameAsync)
 {
 }
Ejemplo n.º 10
0
 public AuthenticatorExtensions(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null, bool isUsingNativeUI = false) : base(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, getUsernameAsync, isUsingNativeUI)
 {
 }
Ejemplo n.º 11
0
 public DisqusAuthenticator(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync)
     : base(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, getUsernameAsync)
 {
     this.clientId     = clientId;
     this.clientSecret = clientSecret;
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Xamarin.Auth.OAuth1Authenticator"/> class.
        /// </summary>
        /// <param name='consumerKey'>
        /// Consumer key.
        /// </param>
        /// <param name='consumerSecret'>
        /// Consumer secret.
        /// </param>
        /// <param name='requestTokenUrl'>
        /// Request token URL.
        /// </param>
        /// <param name='authorizeUrl'>
        /// Authorize URL.
        /// </param>
        /// <param name='accessTokenUrl'>
        /// Access token URL.
        /// </param>
        /// <param name='callbackUrl'>
        /// Callback URL.
        /// </param>
        /// <param name='getUsernameAsync'>
        /// Method used to fetch the username of an account
        /// after it has been successfully authenticated.
        /// </param>
        public OAuth1Authenticator
        (
            string consumerKey,
            string consumerSecret,
            Uri requestTokenUrl,
            Uri authorizeUrl,
            Uri accessTokenUrl,
            Uri callbackUrl,
            GetUsernameAsyncFunc getUsernameAsync = null,
            bool isUsingNativeUI = false
        )
            : base(authorizeUrl, callbackUrl)
        {
            this.is_using_native_ui = isUsingNativeUI;

            if (string.IsNullOrEmpty(consumerKey))
            {
                throw new ArgumentException("consumerKey must be provided", "consumerKey");
            }
            this.consumerKey = consumerKey;

            if (string.IsNullOrEmpty(consumerSecret))
            {
                throw new ArgumentException("consumerSecret must be provided", "consumerSecret");
            }
            this.consumerSecret = consumerSecret;

            if (requestTokenUrl == null)
            {
                throw new ArgumentNullException("requestTokenUrl");
            }
            this.requestTokenUrl = requestTokenUrl;

            if (authorizeUrl == null)
            {
                throw new ArgumentNullException("authorizeUrl");
            }
            this.authorizeUrl = authorizeUrl;

            if (accessTokenUrl == null)
            {
                throw new ArgumentNullException("accessTokenUrl");
            }
            this.accessTokenUrl = accessTokenUrl;

            if (callbackUrl == null)
            {
                throw new ArgumentNullException("callbackUrl");
            }
            this.callbackUrl = callbackUrl;

            this.getUsernameAsync = getUsernameAsync;

            this.HttpWebClientFrameworkType = Auth.HttpWebClientFrameworkType.WebRequest;

            #if DEBUG
            StringBuilder sb = new StringBuilder();
            sb.AppendLine($"OAuth1Authenticator ");
            sb.AppendLine($"        IsUsingNativeUI = {IsUsingNativeUI}");
            sb.AppendLine($"        callbackUrl = {callbackUrl}");
            System.Diagnostics.Debug.WriteLine(sb.ToString());
            #endif

            return;
        }
Ejemplo n.º 13
0
        public void OAuth2Authenticator(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null)
        {
            Xamarin.Auth.OAuth2Authenticator auth2 = new BaseOAuth2Authenticator(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, null); // TODO: getUsernameAsync argument not implemented
            auth2.AllowCancel = AllowCancel;
            auth2.Completed  += (sender, eventArgs) =>
            {
                Completed(auth2, new AuthenticatorCompletedEventArgs(new Account(eventArgs.Account, eventArgs.Account.Properties, eventArgs.Account.Username)));
            };
#if __ANDROID__
            Android.Content.Intent intent = auth2.GetUI(Auth.context);
            Auth.context.StartActivity(intent);
#elif __IOS__
            UIKit.UIViewController vc = auth2.GetUI();
            Auth.dialog.PresentViewController(vc, true, null);
#elif SILVERLIGHT
            Uri uri = auth2.GetUI();
            NavigationService.Navigate(uri);
#endif
        }
        /// <summary>
        /// Initializes a new instance <see cref="Xamarin.Auth.OAuth2Authenticator"/>
        /// that authenticates using authorization codes (code).
        /// </summary>
        /// <param name='clientId'>
        /// Client identifier.
        /// </param>
        /// <param name='clientSecret'>
        /// Client secret.
        /// </param>
        /// <param name='scope'>
        /// Authorization scope.
        /// </param>
        /// <param name='authorizeUrl'>
        /// Authorize URL.
        /// </param>
        /// <param name='redirectUrl'>
        /// Redirect URL.
        /// </param>
        /// <param name='accessTokenUrl'>
        /// URL used to request access tokens after an authorization code was received.
        /// </param>
        /// <param name='getUsernameAsync'>
        /// Method used to fetch the username of an account
        /// after it has been successfully authenticated.
        /// </param>
        public CustomOAuth2Authenticator(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null)
            : this(clientId, scope, redirectUrl, redirectUrl, clientSecret, accessTokenUrl)
        {
            if (string.IsNullOrEmpty(clientSecret))
            {
                throw new ArgumentException("clientSecret must be provided", "clientSecret");
            }

            if (accessTokenUrl == null)
            {
                throw new ArgumentNullException("accessTokenUrl");
            }

            this.getUsernameAsync = getUsernameAsync;
        }
Ejemplo n.º 15
0
 public BaseOAuth2Authenticator(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null) : base(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl)
 {
     this.replacementUrlFormat = null; // replacementUrlFormat not implemented
 }
Ejemplo n.º 16
0
        public void OAuth1Authenticator(string consumerKey, string consumerSecret, Uri requestTokenUrl, Uri authorizeUrl, Uri accessTokenUrl, Uri callbackUrl, GetUsernameAsyncFunc getUsernameAsync)
        {
            Xamarin.Auth.OAuth1Authenticator auth1 = new Xamarin.Auth.OAuth1Authenticator(consumerKey, consumerSecret, requestTokenUrl, authorizeUrl, accessTokenUrl, callbackUrl, null); // TODO: getUsernameAsync argument not implemented
            auth1.AllowCancel = AllowCancel;
            auth1.Completed += (sender, eventArgs) =>
            {
                Completed(auth1, new AuthenticatorCompletedEventArgs(new Account(eventArgs.Account, eventArgs.Account.Properties, eventArgs.Account.Username)));
            };
            auth1.Error += (sender, eventArgs) =>
            {
                Error(sender, new AuthenticatorErrorEventArgs(eventArgs.Message, eventArgs.Exception));
            };
#if __ANDROID__
            Android.Content.Intent intent = auth1.GetUI(Auth.context);
            Auth.context.StartActivity(intent);
#elif __IOS__
            UIKit.UIViewController vc = auth1.GetUI();
	        Auth.dialog.PresentViewController(vc, true, null);
#elif SILVERLIGHT
            Uri uri = auth1.GetUI();
	        NavigationService.Navigate(uri);
#endif
        }
Ejemplo n.º 17
0
		public OAuth1PreAAuthenticator (string consumerKey, string consumerSecret, Uri requestTokenUrl, Uri authorizeUrl, Uri accessTokenUrl, Uri callbackUrl, GetUsernameAsyncFunc getUsernameAsync = null)
		: base (consumerKey, consumerSecret, requestTokenUrl, authorizeUrl, accessTokenUrl, callbackUrl, getUsernameAsync) { }
        public RefreshOAuth2Authenticator(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null)
            : this(redirectUrl, clientSecret, accessTokenUrl)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentException("clientId must be provided", nameof(clientId));
            }
            this.clientId = clientId;

            if (string.IsNullOrEmpty(clientSecret))
            {
                throw new ArgumentException("clientSecret must be provided", nameof(clientSecret));
            }
            this.clientSecret = clientSecret;

            this.scope = scope ?? "";

            if (authorizeUrl == null)
            {
                throw new ArgumentNullException(nameof(authorizeUrl));
            }
            this.authorizeUrl = authorizeUrl;

            if (accessTokenUrl == null)
            {
                throw new ArgumentNullException(nameof(accessTokenUrl));
            }
            this.accessTokenUrl = accessTokenUrl;

            this.redirectUrl = redirectUrl;

            this.getUsernameAsync = getUsernameAsync;
        }
Ejemplo n.º 19
0
 public BaseOAuth2Authenticator(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null) : base(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl)
 {
     this.replacementUrlFormat = null; // replacementUrlFormat not implemented
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance <see cref="Xamarin.Auth.OAuth2Authenticator"/>
        /// that authenticates using authorization codes (code).
        /// </summary>
        /// <param name='clientId'>
        /// Client identifier.
        /// </param>
        /// <param name='clientSecret'>
        /// Client secret.
        /// </param>
        /// <param name='scope'>
        /// Authorization scope.
        /// </param>
        /// <param name='authorizeUrl'>
        /// Authorize URL.
        /// </param>
        /// <param name='redirectUrl'>
        /// Redirect URL.
        /// </param>
        /// <param name='accessTokenUrl'>
        /// URL used to request access tokens after an authorization code was received.
        /// </param>
        /// <param name='getUsernameAsync'>
        /// Method used to fetch the username of an account
        /// after it has been successfully authenticated.
        /// </param>
        public OAuth2Authenticator
        (
            string clientId,
            string clientSecret,
            string scope,
            Uri authorizeUrl,
            Uri redirectUrl,
            Uri accessTokenUrl,
            GetUsernameAsyncFunc getUsernameAsync = null,
            bool isUsingNativeUI = false
        )
            : this(redirectUrl, clientSecret, accessTokenUrl)
        {
            this.is_using_native_ui = isUsingNativeUI;

            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentException("clientId must be provided", "clientId");
            }
            if (authorizeUrl == null)
            {
                throw new ArgumentNullException("authorizeUrl");
            }
            if (accessTokenUrl == null)
            {
                throw new ArgumentNullException("accessTokenUrl");
            }
            if (redirectUrl == null)
            {
                throw new ArgumentNullException("redirectUrl");
            }


            if (string.IsNullOrEmpty(clientSecret))
            {
                /*
                 *  https://tools.ietf.org/html/rfc6749#section-2.3.1
                 *
                 *  RFC6749 2.3.1 Client Password
                 *
                 *  Alternatively, the authorization server MAY support including the
                 *  client credentials in the request-body using the following
                 *  parameters:
                 *
                 *  client_id
                 *               REQUIRED.The client identifier issued to the client during
                 *               the registration process described by Section 2.2.
                 *
                 *  client_secret
                 *               REQUIRED.  The client secret.The client MAY omit the
                 *               parameter if the client secret is an empty string.
                 *
                 *
                 *  Including the client credentials in the request-body using the two
                 *  parameters is NOT RECOMMENDED and SHOULD be limited to clients unable
                 *  to directly utilize the HTTP Basic authentication scheme(or other
                 *  password-based HTTP authentication schemes).  The parameters can only
                 *  be transmitted in the request-body and MUST NOT be included in the
                 *  request URI.
                 *
                 *  For example, a request to refresh an access token(Section 6) using
                 *  the body parameters(with extra line breaks for display purposes
                 *  only):
                 *
                 *  Google for Installed Apps(Mobile, NativeUI) is Authorization Code Grant Flow
                 *  2 Steps Flow
                 *  2nd step does not send Client Secret(null || Empty)
                 *  OK according to the RFC
                 *
                 *              //throw new ArgumentException("clientSecret must be provided", "clientSecret");
                 */

                System.Diagnostics.Debug.WriteLine(this.ToString());
            }

            this.clientId       = clientId;             // required
            this.clientSecret   = clientSecret;         // optional
            this.authorizeUrl   = authorizeUrl;         // required
            this.redirectUrl    = redirectUrl;          // optional
            this.accessTokenUrl = accessTokenUrl;       // optional - required for Authorization Code Grant
            this.scope          = scope ?? "";          // optional

            this.getUsernameAsync = getUsernameAsync;   // Xamarin.legacy

            return;
        }
 public CustomOAuth2Authenticator(string clientId, string scope, Uri authorizeUrl, Uri redirectUrl, GetUsernameAsyncFunc getUsernameAsync = null, bool isUsingNativeUI = false) : base(clientId, scope, authorizeUrl, redirectUrl, getUsernameAsync, isUsingNativeUI)
 {
 }
 public CustomOAuth1Authenticator(string consumerKey, string consumerSecret, Uri requestTokenUrl, Uri authorizeUrl, Uri accessTokenUrl, Uri callbackUrl, GetUsernameAsyncFunc getUsernameAsync = null, bool isUsingNativeUI = false) : base(consumerKey, consumerSecret, requestTokenUrl, authorizeUrl, accessTokenUrl, callbackUrl, getUsernameAsync, isUsingNativeUI)
 {
 }
        /// <summary>
        /// Initializes a new <see cref="Xamarin.Auth.OAuth2Authenticator"/>
        /// that authenticates using implicit granting (token).
        /// </summary>
        /// <param name='clientId'>
        /// Client identifier.
        /// </param>
        /// <param name='scope'>
        /// Authorization scope.
        /// </param>
        /// <param name='authorizeUrl'>
        /// Authorize URL.
        /// </param>
        /// <param name='redirectUrl'>
        /// Redirect URL.
        /// </param>
        /// <param name='getUsernameAsync'>
        /// Method used to fetch the username of an account
        /// after it has been successfully authenticated.
        /// </param>
        public CustomOAuth2Authenticator(string clientId, string scope, Uri authorizeUrl, Uri redirectUrl, GetUsernameAsyncFunc getUsernameAsync = null)
            : this(clientId, scope, authorizeUrl, redirectUrl, null, null)
        {
            if (authorizeUrl == null)
            {
                throw new ArgumentNullException("authorizeUrl");
            }
            if (redirectUrl == null)
            {
                throw new ArgumentNullException("redirectUrl");
            }

            ClientId              = clientId;
            AccessTokenUrl        = null;
            this.getUsernameAsync = getUsernameAsync;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance <see cref="Xamarin.Auth.OAuth2Authenticator"/>
        /// that authenticates using authorization codes (code).
        /// </summary>
        /// <param name='clientId'>
        /// Client identifier.
        /// </param>
        /// <param name='clientSecret'>
        /// Client secret.
        /// </param>
        /// <param name='scope'>
        /// Authorization scope.
        /// </param>
        /// <param name='authorizeUrl'>
        /// Authorize URL.
        /// </param>
        /// <param name='redirectUrl'>
        /// Redirect URL.
        /// </param>
        /// <param name='accessTokenUrl'>
        /// URL used to request access tokens after an authorization code was received.
        /// </param>
        /// <param name='getUsernameAsync'>
        /// Method used to fetch the username of an account
        /// after it has been successfully authenticated.
        /// </param>
        public OAuth2Authenticator
        (
            string clientId,
            string clientSecret,
            string scope,
            Uri authorizeUrl,
            Uri redirectUrl,
            Uri accessTokenUrl,
            GetUsernameAsyncFunc getUsernameAsync = null,
            bool isUsingNativeUI = false
        )
            : this(redirectUrl, clientSecret, accessTokenUrl)
        {
            this.is_using_native_ui = isUsingNativeUI;

            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentException("clientId must be provided", "clientId");
            }
            this.clientId = clientId;

            if (string.IsNullOrEmpty(clientSecret))
            {
                //  Google for Installed Apps (Mobile)
                //  is Authorization Grant Flow (Explicit)
                //  2 Step Flow
                //  2nd step does not send Client Secret (null || Empty)
                //throw new ArgumentException("clientSecret must be provided", "clientSecret");

                #if DEBUG
                StringBuilder sb = new StringBuilder();
                sb.AppendLine($" ");
                sb.AppendLine($"        clientSecret   = null || Empty");
                sb.AppendLine($"        accessTokenUrl = {accessTokenUrl}");
                sb.AppendLine($"        Google for Installed Apps");
                sb.AppendLine($"        redirectUrl    = {redirectUrl}");
                System.Diagnostics.Debug.WriteLine(sb.ToString());
                #endif
            }
            this.clientSecret = clientSecret;

            this.scope = scope ?? "";

            if (authorizeUrl == null)
            {
                throw new ArgumentNullException("authorizeUrl");
            }
            this.authorizeUrl = authorizeUrl;

            if (redirectUrl == null)
            {
                throw new ArgumentNullException("redirectUrl");
            }
            this.redirectUrl = redirectUrl;

            if (accessTokenUrl == null)
            {
                throw new ArgumentNullException("accessTokenUrl");
            }
            this.accessTokenUrl = accessTokenUrl;

            this.getUsernameAsync = getUsernameAsync;

            return;
        }
Ejemplo n.º 25
0
 public MixRadioAuth(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null)
     : base(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, getUsernameAsync)
 {
 }
Ejemplo n.º 26
0
        public void OAuth2Authenticator(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null)
        {
            Xamarin.Auth.OAuth2Authenticator auth2 = new BaseOAuth2Authenticator(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, null); // TODO: getUsernameAsync argument not implemented
            auth2.AllowCancel = AllowCancel;
            auth2.Completed += (sender, eventArgs) =>
            {
                Completed(auth2, new AuthenticatorCompletedEventArgs(new Account(eventArgs.Account, eventArgs.Account.Properties, eventArgs.Account.Username)));
            };
#if __ANDROID__
            Android.Content.Intent intent = auth2.GetUI(Auth.context);
            Auth.context.StartActivity(intent);
#elif __IOS__
            UIKit.UIViewController vc = auth2.GetUI();
	        Auth.dialog.PresentViewController(vc, true, null);
#elif SILVERLIGHT
            Uri uri = auth2.GetUI();
	        NavigationService.Navigate(uri);
#endif
        }
Ejemplo n.º 27
0
            public DropboxAuthenticator(bool embedded, string consumerKey, string consumerSecret, Uri requestTokenUrl, Uri authorizeUrl, Uri accessTokenUrl, Uri callbackUrl, GetUsernameAsyncFunc getUsernameAsync = null)
                : base(consumerKey, consumerSecret, requestTokenUrl, authorizeUrl, accessTokenUrl, callbackUrl, getUsernameAsync)
            {
                Embedded = embedded;
                Title    = "Connect Dropbox";

                this.authorizeUrl = embedded ? new Uri(authorizeUrl, "?embedded=1") : authorizeUrl;
            }
Ejemplo n.º 28
0
			public DisqusAuthenticator(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync)
				: base (clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, getUsernameAsync)
			{
				this.clientId = clientId;
				this.clientSecret = clientSecret;
			}
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="clientId"></param>
 /// <param name="scope"></param>
 /// <param name="authorizeUrl"></param>
 /// <param name="redirectUrl"></param>
 /// <param name="getUsernameAsync"></param>
 public CustomOAuth2Authenticator(string clientId, string scope, Uri authorizeUrl, Uri redirectUrl, GetUsernameAsyncFunc getUsernameAsync = null)
     : base(clientId, scope, authorizeUrl, redirectUrl, getUsernameAsync)
 {
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OAuth2AuthenticatorWithGrant"/> class.
 /// </summary>
 /// <param name="clientId">The client identifier.</param>
 /// <param name="clientSecret">The client secret.</param>
 /// <param name="scope">The scope.</param>
 /// <param name="authorizeUrl">The authorize URL.</param>
 /// <param name="redirectUrl">The redirect URL.</param>
 /// <param name="accessTokenUrl">The access token URL.</param>
 /// <param name="getUsernameAsync">The get username asynchronous.</param>
 /// <param name="isUsingNativeUI">if set to <c>true</c> [is using native UI].</param>
 public OAuth2AuthenticatorWithGrant(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null, bool isUsingNativeUI = false) : base(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, getUsernameAsync, isUsingNativeUI)
 {
     _client = new HttpClient();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="clientId"></param>
 /// <param name="clientSecret"></param>
 /// <param name="scope"></param>
 /// <param name="authorizeUrl"></param>
 /// <param name="redirectUrl"></param>
 /// <param name="accessTokenUrl"></param>
 /// <param name="getUsernameAsync"></param>
 public CustomOAuth2Authenticator(string clientId, string clientSecret, string scope, Uri authorizeUrl, Uri redirectUrl, Uri accessTokenUrl, GetUsernameAsyncFunc getUsernameAsync = null)
     : base(clientId, clientSecret, scope, authorizeUrl, redirectUrl, accessTokenUrl, getUsernameAsync)
 {
     IgnoreErrorsWhenCompleted = true;
 }
Ejemplo n.º 32
0
 public OAuth1PreAAuthenticator(string consumerKey, string consumerSecret, Uri requestTokenUrl, Uri authorizeUrl, Uri accessTokenUrl, Uri callbackUrl, GetUsernameAsyncFunc getUsernameAsync = null)
     : base(consumerKey, consumerSecret, requestTokenUrl, authorizeUrl, accessTokenUrl, callbackUrl, getUsernameAsync)
 {
 }
Ejemplo n.º 33
0
        public void OAuth1Authenticator(string consumerKey, string consumerSecret, Uri requestTokenUrl, Uri authorizeUrl, Uri accessTokenUrl, Uri callbackUrl, GetUsernameAsyncFunc getUsernameAsync)
        {
            Xamarin.Auth.OAuth1Authenticator auth1 = new Xamarin.Auth.OAuth1Authenticator(consumerKey, consumerSecret, requestTokenUrl, authorizeUrl, accessTokenUrl, callbackUrl, null); // TODO: getUsernameAsync argument not implemented
            auth1.AllowCancel = AllowCancel;
            auth1.Completed  += (sender, eventArgs) =>
            {
                Completed(auth1, new AuthenticatorCompletedEventArgs(new Account(eventArgs.Account, eventArgs.Account.Properties, eventArgs.Account.Username)));
            };
            auth1.Error += (sender, eventArgs) =>
            {
                Error(sender, new AuthenticatorErrorEventArgs(eventArgs.Message, eventArgs.Exception));
            };
#if __ANDROID__
            Android.Content.Intent intent = auth1.GetUI(Auth.context);
            Auth.context.StartActivity(intent);
#elif __IOS__
            UIKit.UIViewController vc = auth1.GetUI();
            Auth.dialog.PresentViewController(vc, true, null);
#elif SILVERLIGHT
            Uri uri = auth1.GetUI();
            NavigationService.Navigate(uri);
#endif
        }