예제 #1
0
        /// <summary>
        /// Returns the authorization URL of the specified provider, query parameters and return URL.
        /// </summary>
        /// <param name="clientName">
        /// The provider name, through which it is necessary to authorize the current user; or the name of the registered client.
        /// </param>
        /// <param name="parameters">Additional parameters to be passed to the authorization URL.</param>
        /// <param name="returnUrl">The address to which the user is redirected after the authorization.</param>
        /// <param name="state">Custom state associated with authorization request.</param>
        /// <exception cref="NullHttpContextException">
        /// The exception that is thrown when you try to access methods that are designed for web projects.
        /// </exception>
        public static string GetAuthorizationUrl(ClientName clientName, NameValueCollection parameters, string returnUrl, object state)
        {
            if (!OAuthManager.RegisteredClients.ContainsKey(clientName))
            {
                throw new ClientIsNotRegisteredException();
            }

            // get normal client name
            clientName = OAuthManager.RegisteredClients.Keys.First(k => k == clientName);

            // create new instance of the client
            var client = OAuthManager.RegisteredClients[clientName].Clone(parameters, returnUrl);

            // add request
            OAuthManager.AddRequest(client.State, clientName, client, state);

            // return url
            return(client.AuthorizationUrl);
        }
예제 #2
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);
 }