예제 #1
0
        /// <summary>
        /// Registers the specified client in the application.
        /// </summary>
        /// <param name="clientName">The provider name. And may also contain any client name for for division into groups.</param>
        /// <param name="clientId">The application identifier obtained from the provider website.</param>
        /// <param name="clientSecret">The application secret key obtained from the provider website.</param>
        /// <param name="initArgs">Additional parameters to be passed to the constructor of the client class.</param>
        /// <param name="scope">List of scope that will be requested from the provider. Only for OAuth 2.0.</param>
        /// <param name="parameters">Additional parameters that will be transferred to the provider website.</param>
        /// <exception cref="ArgumentNullException"><paramref name="clientName"/>, <paramref name="clientId"/> or <paramref name="clientSecret"/> is <b>null</b> or <b>empty</b>.</exception>
        /// <exception cref="UnknownProviderException">Provider not found by <paramref name="clientName"/>.</exception>
        /// <exception cref="NotSupportedException">The <paramref name="clientName"/> not suppored <paramref name="scope"/>.</exception>
        /// <example>
        /// <code lang="C#">
        /// OAuthManager.RegisterClient
        /// (
        ///   "google",
        ///   "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
        ///   "AeEbEGQqoKgOZb41JUVLvEJL"
        /// );
        ///
        /// OAuthManager.RegisterClient
        /// (
        ///   "facebook"
        ///   "1435890426686808",
        ///   "c6057dfae399beee9e8dc46a4182e8fd"
        /// );
        /// </code>
        /// <code lang="VB">
        /// OAuthManager.RegisterClient _
        /// (
        ///   "google",
        ///   "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
        ///   "AeEbEGQqoKgOZb41JUVLvEJL"
        /// )
        ///
        /// OAuthManager.RegisterClient _
        /// (
        ///   "facebook",
        ///   "1435890426686808",
        ///   "c6057dfae399beee9e8dc46a4182e8fd"
        /// )
        /// </code>
        /// <para>
        /// You can register multiple clients to a single provider.
        /// The following example shows how to do it.
        /// </para>
        /// <code lang="C#">
        /// var clientName = ClientName.Create("Debug", "Facebook");
        ///
        /// OAuthManager.RegisterClient
        /// (
        ///   clientName
        ///   "000000000000000000",
        ///   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
        /// );
        ///
        /// clientName = ClientName.Create("Any name", "Facebook");
        ///
        /// OAuthManager.RegisterClient
        /// (
        ///   clientName
        ///   "111111111111111111",
        ///   "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
        /// );
        /// </code>
        /// <code lang="VB">
        /// Dim name As ClientName = ClientName.Create("Debug", "Facebook")
        ///
        /// OAuthManager.RegisterClient _
        /// (
        ///   name,
        ///   "000000000000000000",
        ///   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
        /// )
        ///
        /// name As ClientName = ClientName.Create("Any name", "Facebook")
        ///
        /// OAuthManager.RegisterClient _
        /// (
        ///   name,
        ///   "111111111111111111",
        ///   "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
        /// )
        /// </code>
        /// </example>
        public static void RegisterClient(ClientName clientName, string clientId, string clientSecret, string scope = null, NameValueCollection parameters = null, object[] initArgs = null)
        {
            if (String.IsNullOrEmpty(clientName))
            {
                throw new ArgumentNullException("clientName");
            }
            if (String.IsNullOrEmpty(clientId))
            {
                throw new ArgumentNullException("clientId");
            }
            if (String.IsNullOrEmpty(clientSecret))
            {
                throw new ArgumentNullException("clientSecret");
            }

            // searching provider by name
            if (!OAuthManager.AllClients.ContainsKey(clientName.ProviderName))
            {
                throw new UnknownProviderException("Provider [{0}] not found. Please, check provider name.", clientName.ProviderName);
            }

            // init parameters
            var parm = new ArrayList();

            parm.Add(clientId);
            parm.Add(clientSecret);

            if (initArgs != null && initArgs.Length > 0)
            {
                parm.AddRange(initArgs);
            }

            // creating client instance
            OAuthBase client = Activator.CreateInstance(OAuthManager.AllClients[clientName.ProviderName], parm.ToArray()) as OAuthBase;

            if (!String.IsNullOrEmpty(scope))
            {
                if (client.GetType().BaseType != typeof(OAuth2Client))
                {
                    throw new NotSupportedException("The scope supported only for OAuth 2.0 clients.");
                }
                ((OAuth2Client)client).Scope = scope;
            }

            if (parameters != null)
            {
                client.Parameters = parameters;
            }

            // add client
            OAuthManager.RegisterClient(clientName.Key, client);
        }
예제 #2
0
 /// <summary>
 /// Registers the specified client in the application.
 /// </summary>
 /// <param name="providerName">The provider name.</param>
 /// <param name="clientId">The application identifier obtained from the provider website.</param>
 /// <param name="clientSecret">The application secret key obtained from the provider website.</param>
 /// <param name="scope">List of scope that will be requested from the provider. Only for OAuth 2.0.</param>
 /// <param name="initArgs">Additional parameters to be passed to the constructor of the client class.</param>
 /// <param name="parameters">Additional parameters that will be transferred to the provider website.</param>
 /// <exception cref="ArgumentNullException"><paramref name="providerName"/>, <paramref name="clientId"/> or <paramref name="clientSecret"/> is <b>null</b> or <b>empty</b>.</exception>
 /// <exception cref="UnknownProviderException">Provider not found by <paramref name="providerName"/>.</exception>
 /// <exception cref="NotSupportedException">The <paramref name="providerName"/> not suppored <paramref name="scope"/>.</exception>
 /// <example>
 /// <code lang="C#">
 /// OAuthManager.RegisterClient
 /// (
 ///   "google",
 ///   "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
 ///   "AeEbEGQqoKgOZb41JUVLvEJL"
 /// );
 ///
 /// OAuthManager.RegisterClient
 /// (
 ///   "facebook"
 ///   "1435890426686808",
 ///   "c6057dfae399beee9e8dc46a4182e8fd"
 /// );
 /// </code>
 /// <code lang="VB">
 /// OAuthManager.RegisterClient _
 /// (
 ///   "google",
 ///   "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
 ///   "AeEbEGQqoKgOZb41JUVLvEJL"
 /// )
 ///
 /// OAuthManager.RegisterClient _
 /// (
 ///   "facebook",
 ///   "1435890426686808",
 ///   "c6057dfae399beee9e8dc46a4182e8fd"
 /// )
 /// </code>
 /// </example>
 public static void RegisterClient(string providerName, string clientId, string clientSecret, string scope = null, NameValueCollection parameters = null, object[] initArgs = null)
 {
     OAuthManager.RegisterClient(ClientName.Parse(providerName), clientId, clientSecret, scope, parameters, initArgs);
 }
예제 #3
0
 /// <summary>
 /// Registers the specified client in the application.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <param name="clientName">The any name of the client. For example: Test, Release, Project #1, Ku!, Example.org etc.</param>
 /// <exception cref="ArgumentNullException"><paramref name="client"/> is <b>null</b> or <b>empty</b>.</exception>
 /// <exception cref="DuplicateProviderException">If you attempt to register the already registered client.</exception>
 /// <example>
 /// <code lang="C#">
 /// OAuthManager.RegisterClient
 /// (
 ///   "Test",
 ///   new GoogleClient
 ///   (
 ///     "00000000000000.apps.googleusercontent.com",
 ///     "000000000000000000000000"
 ///   )
 /// );
 ///
 /// OAuthManager.RegisterClient
 /// (
 ///   "Test",
 ///   new FacebookClient
 ///   (
 ///     "00000000000000",
 ///     "000000000000000000000000"
 ///   )
 /// );
 ///
 /// OAuthManager.RegisterClient
 /// (
 ///   "Release",
 ///   new GoogleClient
 ///   (
 ///     "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
 ///     "AeEbEGQqoKgOZb41JUVLvEJL"
 ///   )
 /// );
 ///
 /// OAuthManager.RegisterClient
 /// (
 ///   "Release",
 ///   new FacebookClient
 ///   (
 ///     "1435890426686808",
 ///     "c6057dfae399beee9e8dc46a4182e8fd"
 ///   )
 /// );
 /// </code>
 /// <code lang="VB">
 /// OAuthManager.RegisterClient _
 /// (
 ///   "Test",
 ///   New GoogleClient _
 ///   (
 ///     "00000000000000.apps.googleusercontent.com",
 ///     "000000000000000000000000"
 ///   )
 /// )
 ///
 /// OAuthManager.RegisterClient _
 /// (
 ///   "Test",
 ///   New FacebookClient _
 ///   (
 ///     "00000000000000",
 ///     "000000000000000000000000"
 ///   )
 /// )
 ///
 /// OAuthManager.RegisterClient _
 /// (
 ///   "Release",
 ///   New GoogleClient _
 ///   (
 ///     "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
 ///     "AeEbEGQqoKgOZb41JUVLvEJL"
 ///   )
 /// )
 ///
 /// OAuthManager.RegisterClient _
 /// (
 ///   "Release",
 ///   New FacebookClient _
 ///   (
 ///     "1435890426686808",
 ///     "c6057dfae399beee9e8dc46a4182e8fd"
 ///   )
 /// )
 /// </code>
 /// </example>
 public static void RegisterClient(ClientName clientName, OAuthBase client)
 {
     OAuthManager.RegisterClient(clientName.Key, client);
 }
예제 #4
0
 /// <summary>
 /// Registers the specified client in the application.
 /// </summary>
 /// <param name="providerName">The provider name.</param>
 /// <param name="clientId">The application identifier obtained from the provider website.</param>
 /// <param name="clientSecret">The application secret key obtained from the provider website.</param>
 /// <exception cref="ArgumentNullException"><paramref name="providerName"/>, <paramref name="clientId"/> or <paramref name="clientSecret"/> is <b>null</b> or <b>empty</b>.</exception>
 /// <exception cref="UnknownProviderException">Provider not found by <paramref name="providerName"/>.</exception>
 /// <example>
 /// <code lang="C#">
 /// OAuthManager.RegisterClient
 /// (
 ///   "google",
 ///   "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
 ///   "AeEbEGQqoKgOZb41JUVLvEJL"
 /// );
 ///
 /// OAuthManager.RegisterClient
 /// (
 ///   "facebook"
 ///   "1435890426686808",
 ///   "c6057dfae399beee9e8dc46a4182e8fd"
 /// );
 /// </code>
 /// <code lang="VB">
 /// OAuthManager.RegisterClient _
 /// (
 ///   "google",
 ///   "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
 ///   "AeEbEGQqoKgOZb41JUVLvEJL"
 /// )
 ///
 /// OAuthManager.RegisterClient _
 /// (
 ///   "facebook",
 ///   "1435890426686808",
 ///   "c6057dfae399beee9e8dc46a4182e8fd"
 /// )
 /// </code>
 /// </example>
 public static void RegisterClient(string providerName, string clientId, string clientSecret)
 {
     OAuthManager.RegisterClient(ClientName.Parse(providerName), clientId, clientSecret, null, null, null);
 }
예제 #5
0
 /// <summary>
 /// Registers the specified client in the application.
 /// </summary>
 /// <param name="client">The client instance.</param>
 /// <exception cref="ArgumentNullException"><paramref name="client"/> is <b>null</b> or <b>empty</b>.</exception>
 /// <exception cref="DuplicateProviderException">If you attempt to register the already registered client.</exception>
 /// <example>
 /// <code lang="C#">
 /// OAuthManager.RegisterClient
 /// (
 ///   new GoogleClient
 ///   (
 ///     "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
 ///     "AeEbEGQqoKgOZb41JUVLvEJL"
 ///   )
 /// );
 ///
 /// OAuthManager.RegisterClient
 /// (
 ///   new FacebookClient
 ///   (
 ///     "1435890426686808",
 ///     "c6057dfae399beee9e8dc46a4182e8fd"
 ///   )
 /// );
 /// </code>
 /// <code lang="VB">
 /// OAuthManager.RegisterClient _
 /// (
 ///   New GoogleClient _
 ///   (
 ///     "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com",
 ///     "AeEbEGQqoKgOZb41JUVLvEJL"
 ///   )
 /// )
 ///
 /// OAuthManager.RegisterClient _
 /// (
 ///   New FacebookClient _
 ///   (
 ///     "1435890426686808",
 ///     "c6057dfae399beee9e8dc46a4182e8fd"
 ///   )
 /// )
 /// </code>
 /// </example>
 public static void RegisterClient(OAuthBase client)
 {
     OAuthManager.RegisterClient(String.Empty, client);
 }