/// <summary>
    /// Initializes a new instance of the <see cref="OAuthRequest"/> class.
    /// </summary>
    /// <param name="client">The instance of the OAuth client.</param>
    /// <param name="clientName">The client name.</param>
    public OAuthRequest(ClientName clientName, OAuthBase client)
    {
      /* is is not possible
      if (client == null)
      {
        throw new ArgumentNullException("client");
      }
      */

      if (String.IsNullOrEmpty(clientName))
      {
        clientName = client.ProviderName;
      }

      _ClientName = clientName;
      _Client = client;
    }
Example #2
0
        /// <summary>
        /// Creates a shallow copy of the current object.
        /// </summary>
        /// <param name="parameters">The query parameters for new copy object.</param>
        /// <param name="returnUrl">The new return URL for new copy object.</param>
        /// <returns>A shallow copy of the current object.</returns>
        /// <remarks>
        /// <para>Method creates a copy of the current object, removes tokens, change the return address, query parameters and state.</para>
        /// <para>Unfortunately, I made a mistake in architecture, so I had to make this method.</para>
        /// </remarks>
        /// <seealso cref="Clone()"/>
        public OAuthBase Clone(NameValueCollection parameters, string returnUrl)
        {
            OAuthBase result = this.Clone() as OAuthBase;

            if (returnUrl != null)
            {
                result.ReturnUrl = returnUrl;
            }
            if (parameters != null)
            {
                if (result.Parameters.Count <= 0)
                {
                    result.Parameters = parameters;
                }
                else
                {
                    foreach (string key in parameters.Keys)
                    {
                        result.Parameters[key] = parameters[key];
                    }
                }
            }
            return(result);
        }
Example #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);
 }
Example #4
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);
 }
Example #5
0
 /// <summary>
 /// Adds the specified request to the collection.
 /// </summary>
 /// <param name="key">The unique request key.</param>
 /// <param name="clientName">The client name.</param>
 /// <param name="client">The client instance.</param>
 /// <param name="state">Custom state associated with authorization request.</param>
 internal static void AddRequest(string key, ClientName clientName, OAuthBase client, object state)
 {
     OAuthManager.RequestsProvider.Add(key, clientName, client, state);
 }
Example #6
0
 /// <summary>
 /// Adds the specified request to the collection.
 /// </summary>
 /// <param name="key">The unique request key.</param>
 /// <param name="clientName">The client name.</param>
 /// <param name="client">The client instance.</param>
 internal static void AddRequest(string key, ClientName clientName, OAuthBase client)
 {
     OAuthManager.AddRequest(key, clientName, client, null);
 }
Example #7
0
 /// <summary>
 /// Adds the specified request to the collection.
 /// </summary>
 /// <param name="key">The unique request key.</param>
 /// <param name="clientName">The client name.</param>
 /// <param name="client">The client instance.</param>
 internal static void AddRequest(string key, ClientName clientName, OAuthBase client)
 {
     OAuthManager.Requests.Add(key, new OAuthRequest(clientName, client));
     _Timer.Start();
 }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OAuthRequest"/> class.
 /// </summary>
 /// <param name="client">The instance of the OAuth client.</param>
 public OAuthRequest(OAuthBase client) : this(null, client, null)
 {
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OAuthRequest"/> class.
 /// </summary>
 /// <param name="client">The instance of the OAuth client.</param>
 /// <param name="clientName">The client name.</param>
 public OAuthRequest(ClientName clientName, OAuthBase client) : this(clientName, client, null)
 {
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OAuthRequest"/> class.
 /// </summary>
 /// <param name="client">The instance of the OAuth client.</param>
 public OAuthRequest(OAuthBase client)
 {
     _Client = client;
 }
    /// <summary>
    /// Registers the specified client in the application. (the main method)
    /// </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(string clientName, OAuthBase client)
    {
      if (client == null) { throw new ArgumentNullException("client"); }

      /*if (client.ProviderName.Equals(ClientName.Parse(clientName).ProviderName, StringComparison.InvariantCultureIgnoreCase))
      {
        // contains provider name
        clientName = ClientName.Escape(ClientName.Parse(clientName).Key);
      }
      else
      {
        clientName = ClientName.Escape(clientName);
      }

      var name = ClientName.Create(ClientName.Parse(clientName).Key ?? ClientName.Unescape(clientName), client.ProviderName);
      */

      var name = ClientName.Create(clientName, client.ProviderName);

      if (_RegisteredClients.ContainsKey(name))
      {
        throw new DuplicateProviderException(name);
      }

      // add client
      _RegisteredClients.Add(name, client);

      // remove from watching 
      // OAuthManager.RemoveRequest(client.State.ToString());
      // --

      // if this is a new client
      if (!OAuthManager.AllClients.ContainsKey(client.ProviderName))
      {
        // add to list
        OAuthManager.AllClients.Add(client.ProviderName, client.GetType());
      }
      /*else
      {
        // check namespace
        if (!client.GetType().Namespace.Equals("Nemiro.OAuth.Clients", StringComparison.InvariantCultureIgnoreCase))
        {
          // overwrite
          OAuthManager.AllClients[client.ProviderName] = client.GetType();
        }
      }*/
    }
 /// <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);
 }
 /// <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);
 }
 /// <summary>
 /// Adds the specified request to the collection.
 /// </summary>
 /// <param name="key">The unique request key.</param>
 /// <param name="clientName">The client name.</param>
 /// <param name="client">The client instance.</param>
 internal static void AddRequest(string key, ClientName clientName, OAuthBase client)
 {
   OAuthManager.Requests.Add(key, new OAuthRequest(clientName, client));
   _Timer.Start();
 }