示例#1
0
        public AuthorizeResult Authorize(Uri url, string username, string password)
        {
            var authServer = new AuthorizationServerDescription
            {
                AuthorizationEndpoint = null, // We are not actually using authorization, just authentication.
                TokenEndpoint = url
            };

            var client = new UserAgentClient(authServer, ClientIdentifier, ClientCredentialApplicator.PostParameter(ClientSecret));

            IAuthorizationState state;

            try
            {
                state = client.ExchangeUserCredentialForToken(username, password);
            }
            catch (Exception e)
            {
                var error = e.Message;

                if (e.InnerException != null)
                    error = string.Format("{0} Inner exception: {1}", error, e.InnerException.Message);

                return new AuthorizeResult
                {
                    Error = error
                };
            }

            return new AuthorizeResult
            {
                AuthorizationState = state
            };
        }
示例#2
0
 private WebServerClient CreateOAuth2Client() {
     var serverDescription = new AuthorizationServerDescription {
         TokenEndpoint = new Uri(tokenEndpointTextBox.Text)
     };
     var client = new WebServerClient(serverDescription, oauth2ClientIdTextBox.Text, oauth2ClientSecretTextBox.Text);
     return (client);
 }
示例#3
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ClientBase"/> class.
		/// </summary>
		/// <param name="authorizationServer">The token issuer.</param>
		/// <param name="clientIdentifier">The client identifier.</param>
		/// <param name="clientSecret">The client secret.</param>
		protected ClientBase(AuthorizationServerDescription authorizationServer, string clientIdentifier = null, string clientSecret = null) {
			Contract.Requires<ArgumentNullException>(authorizationServer != null);
			this.AuthorizationServer = authorizationServer;
			this.Channel = new OAuth2ClientChannel();
			this.ClientIdentifier = clientIdentifier;
			this.ClientSecret = clientSecret;
		}
        public GoogleOAuth2Authorization(ILogger log) : base(log)
        {
            Func<string, string> getConfigVal = (value) =>
                                                (ConfigurationManager.AppSettings.Get(value) ??
                                                 WebConfigurationManager.AppSettings.Get(value) ?? 
                                                 KeyStorage.Get(value));

            try
            {
                ClientID = getConfigVal("mail.googleClientID");
                ClientSecret = getConfigVal("mail.googleClientSecret");

                if (String.IsNullOrEmpty(ClientID)) throw new ArgumentNullException("ClientID");
                if (String.IsNullOrEmpty(ClientSecret)) throw new ArgumentNullException("ClientSecret");
            }
            catch (Exception ex)
            {
                log.Error("GoogleOAuth2Authorization() Exception:\r\n{0}\r\n", ex.ToString());
            }

            RedirectUrl = "urn:ietf:wg:oauth:2.0:oob";
 
            ServerDescription = new AuthorizationServerDescription
            {
                AuthorizationEndpoint = new Uri("https://accounts.google.com/o/oauth2/auth?access_type=offline"),
                TokenEndpoint = new Uri("https://accounts.google.com/o/oauth2/token"),
                ProtocolVersion = DotNetOpenAuth.OAuth2.ProtocolVersion.V20,
            };

            Scope = new List<string>
            {
                "https://mail.google.com/"
            };
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserAgentClient"/> class.
 /// </summary>
 /// <param name="authorizationServer">The token issuer.</param>
 /// <param name="clientIdentifier">The client identifier.</param>
 /// <param name="clientSecret">The client secret.</param>
 public NativeApplicationClient(
     AuthorizationServerDescription authorizationServer,
     string clientIdentifier,
     string clientSecret)
     : base(authorizationServer, clientIdentifier, clientSecret)
 {
 }
 public virtual IAuthorizationState ProcessUserAuthorization(
     WebServerClient authClient, AuthorizationServerDescription authServer, IServiceBase authService)
 {
     return HostContext.Config.StripApplicationVirtualPath
         ? authClient.ProcessUserAuthorization(authService.Request.ToHttpRequestBase())
         : authClient.ProcessUserAuthorization();
 }
示例#7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ClientBase"/> class.
		/// </summary>
		/// <param name="authorizationServer">The token issuer.</param>
		/// <param name="clientIdentifier">The client identifier.</param>
		/// <param name="clientSecret">The client secret.</param>
		protected ClientBase(AuthorizationServerDescription authorizationServer, string clientIdentifier = null, string clientSecret = null) {
			Requires.NotNull(authorizationServer, "authorizationServer");
			this.AuthorizationServer = authorizationServer;
			this.Channel = new OAuth2ClientChannel();
			this.ClientIdentifier = clientIdentifier;
			this.ClientSecret = clientSecret;
		}
示例#8
0
        protected async void Button1_Click(object sender, EventArgs e)
        {
            var authServer = new AuthorizationServerDescription()
            {
                
                TokenEndpoint = new Uri("http://localhost:53022/OAuth/token "),
                ProtocolVersion = ProtocolVersion.V20
            };
            WebServerClient Client= new WebServerClient(authServer, "idefav", "1");

            var code =await Client.GetClientAccessTokenAsync(new string[] { "http://localhost:55045/IService1/DoWork" });
            string token = code.AccessToken;
            Service1Reference.Service1Client service1Client=new Service1Client();
            var httpRequest = (HttpWebRequest)WebRequest.Create(service1Client.Endpoint.Address.Uri);
            ClientBase.AuthorizeRequest(httpRequest,token);
            var httpDetails = new HttpRequestMessageProperty();
            httpDetails.Headers[HttpRequestHeader.Authorization] = httpRequest.Headers[HttpRequestHeader.Authorization];
            
            using (var scope = new OperationContextScope(service1Client.InnerChannel))
            {
                
                if (OperationContext.Current.OutgoingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name))
                {
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpDetails;
                }
                else
                {
                    OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, httpDetails);
                }
                
                Button1.Text= service1Client.DoWork();
            }


        }
示例#9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ClientBase" /> class.
		/// </summary>
		/// <param name="authorizationServer">The token issuer.</param>
		/// <param name="clientIdentifier">The client identifier.</param>
		/// <param name="clientCredentialApplicator">The tool to use to apply client credentials to authenticated requests to the Authorization Server.
		/// May be <c>null</c> for clients with no secret or other means of authentication.</param>
		/// <param name="hostFactories">The host factories.</param>
		protected ClientBase(AuthorizationServerDescription authorizationServer, string clientIdentifier = null, ClientCredentialApplicator clientCredentialApplicator = null, IHostFactories hostFactories = null) {
			Requires.NotNull(authorizationServer, "authorizationServer");
			this.AuthorizationServer = authorizationServer;
			this.Channel = new OAuth2ClientChannel(hostFactories);
			this.ClientIdentifier = clientIdentifier;
			this.ClientCredentialApplicator = clientCredentialApplicator;
		}
 /// <summary>
 ///   Does this instance.
 /// </summary>
 public override void PerformAction()
 {
     authServerDescription = new AuthorizationServerDescription();
     // Add the access_type parameter sot that the RefreshToken is returned along with the AccessTokein
     authServerDescription.AuthorizationEndpoint = new Uri(@"https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force");
     authServerDescription.TokenEndpoint = new Uri(@"https://accounts.google.com/o/oauth2/token");
     authServerDescription.ProtocolVersion = ProtocolVersion.V20;
 }
示例#11
0
 public static AuthorizationServerDescription GetAuthServerDescription()
 {
     var authServerDescription = new AuthorizationServerDescription();
     authServerDescription.AuthorizationEndpoint = new Uri(@"https://accounts.google.com/o/oauth2/auth");
     authServerDescription.TokenEndpoint = new Uri(@"https://accounts.google.com/o/oauth2/token");
     authServerDescription.ProtocolVersion = ProtocolVersion.V20;
     return authServerDescription;
 }
示例#12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientBase"/> class.
 /// </summary>
 /// <param name="authorizationServer">The token issuer.</param>
 /// <param name="clientIdentifier">The client identifier.</param>
 /// <param name="clientCredentialApplicator">
 /// The tool to use to apply client credentials to authenticated requests to the Authorization Server.
 /// May be <c>null</c> for clients with no secret or other means of authentication.
 /// </param>
 protected ClientBase(AuthorizationServerDescription authorizationServer, string clientIdentifier = null, ClientCredentialApplicator clientCredentialApplicator = null)
 {
     Requires.NotNull(authorizationServer, "authorizationServer");
     this.AuthorizationServer        = authorizationServer;
     this.Channel                    = new OAuth2ClientChannel();
     this.ClientIdentifier           = clientIdentifier;
     this.ClientCredentialApplicator = clientCredentialApplicator;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CreateGoogleClientAction"/> class.
 /// </summary>
 /// <param name="authorizationDescription"></param>
 /// <param name="membershipProvider">The build motion provider.</param>
 public CreateGoogleClientAction(AuthorizationServerDescription authorizationDescription, MembershipProviderBase membershipProvider)
     : base(membershipProvider)
 {
     this.authorizationDescription = authorizationDescription;
     //PATTERN: setup in constructor to allow for action validation on fields/properties;
     this.clientId = this.Provider.GoogleClientId;
     this.clientSecret = this.Provider.GoogleClientSecret;
 }
 public HomeController() {
     var authServer = new AuthorizationServerDescription() {
         AuthorizationEndpoint = new Uri("http://localhost:49810/OAuth/Authorise"),
         TokenEndpoint = new Uri("http://localhost:49810/OAuth/Token"),
     };
     this.Client = new UserAgentClient(authServer, "samplewebapiconsumer", "samplesecret");
     this.Authorization = new AuthorizationState();
     this.Authorization.Callback = new Uri("http://localhost:18529/");
 }
示例#15
0
        /// <summary>
        /// Constructor when using the GetAssertionAccessTokenAsync() method.
        /// </summary>
        /// <param name="authorizationServer"></param>
        /// <param name="assertionProvider">This will be queried for the assertion data.</param>
        /// <param name="hostFactories"></param>
        protected ClientBase(AuthorizationServerDescription authorizationServer, IAssertionProvider assertionProvider, IHostFactories hostFactories = null)
        {
            Requires.NotNull(authorizationServer, "authorizationServer");
            this.AuthorizationServer = authorizationServer;
            this.Channel             = new OAuth2ClientChannel(hostFactories);

            // YTML: A bit hacky, but instead of creating a new property, we can just wrap the assertionProvider as a credential applicator.
            this.ClientCredentialApplicator = new ClientCredentialApplicator.AssertionProviderApplicator(assertionProvider);
        }
        private static void Main()
        {
            // DotNetOpenAuth only issues access tokens when the client uses an HTTPS connection. As we will most
            // likely run the server on our local development machine with only a self-signed SSL certificate, setting up 
            // connection to the server will fail as the SSL certificate is considered invalid by the .NET framework. 
            // To circumvent this, we add the line below that will consider all SSL certificates as valid, including
            // self-signed certificaties. Note: this should only be used for testing purposes.
            ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

            // The description of the authorization server to which we will be connecting. The most important component
            // is the token endpoint, which is the URL at which the server listens for token requests
            var authorizationServerDescription = new AuthorizationServerDescription
                                                     {
                                                         TokenEndpoint = new Uri("https://localhost:44303/tokens"),
                                                         ProtocolVersion = ProtocolVersion.V20
                                                     };

            // Create the client with which we will be connecting to the server.
            var userAgentClient = new UserAgentClient(authorizationServerDescription, clientIdentifier: "demo-client-1", clientSecret: "demo-client-secret-1");

            // The scope that we request for the client. Note: this can also be null if we don't want to request any specific 
            // scope or more than one scope if we want to request an access token that is valid for several scopes
            var clientScopes = new[] { "demo-scope-client-1" };

            // Request a new client access token for the specified scopes (http://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4.4)
            // This method will use the client identifier and client secret used when constructing the UserAgentClient instance
            var clientAccessToken = userAgentClient.GetClientAccessToken(clientScopes);

            // Output some information about the retrieved client access token
            Console.WriteLine("[RETRIEVED CLIENT ACCESS TOKEN]");
            Console.WriteLine("Access token: {0}", clientAccessToken.AccessToken);
            Console.WriteLine("Expiration time: {0}", clientAccessToken.AccessTokenExpirationUtc);
            Console.WriteLine("Scope: {0}",  OAuthUtilities.JoinScopes(clientAccessToken.Scope));

            // The scope that we request for the user. Note: this can also be null if we don't want to request any specific 
            // scope or more than one scope if we want to request an access token that is valid for several scopes
            var userScopes = new[] { "demo-scope-1" };

            // Request a new user access token for the specified user and the specified scopes (http://tools.ietf.org/html/draft-ietf-oauth-v2-31#page-35)
            var userAccessToken = userAgentClient.ExchangeUserCredentialForToken("demo-user-1", "demo-user-password-1", userScopes);

            // Output some information about the retrieved user access token
            Console.WriteLine("\n[RETRIEVED USER ACCESS TOKEN]");
            Console.WriteLine("Access token: {0}", userAccessToken.AccessToken);
            Console.WriteLine("Refresh token: {0}", userAccessToken.RefreshToken);
            Console.WriteLine("Expiration time: {0}", userAccessToken.AccessTokenExpirationUtc);
            Console.WriteLine("Scope: {0}", OAuthUtilities.JoinScopes(userAccessToken.Scope));

            var refreshed = userAgentClient.RefreshAuthorization(userAccessToken);

            Console.WriteLine("\n[REFRESHING USER ACCESS TOKEN]");
            Console.WriteLine("Access token refreshed: {0}", refreshed);

            Console.WriteLine("\nPress any key to exit...");
            Console.ReadKey();
        }
示例#17
0
        private static void InitializeWebServerClient()
        {
            var authorizationServer = new AuthorizationServerDescription
            {
                AuthorizationEndpoint = new Uri(authorizationServerUri, "/oauth2/authorize"),
                TokenEndpoint = new Uri(authorizationServerUri, "/api/oauth2/token"),
            };

            _webServerClient = new WebServerClient(authorizationServer, "resource_owner_test", "resource_owner_test");
        }
示例#18
0
 private static void InitializeWebServerClient()
 {
     var authorizationServerUri = new Uri(Paths.AuthorizationServerBaseAddress);
     var authorizationServer = new AuthorizationServerDescription
     {
         AuthorizationEndpoint = new Uri(authorizationServerUri, Paths.AuthorizePath),
         TokenEndpoint = new Uri(authorizationServerUri, Paths.TokenPath)
     };
     _webServerClient = new WebServerClient(authorizationServer, Clients.Client1.Id, Clients.Client1.Secret);
 }
 static GoogleAuthenticationServer()
 {
     // Set the auth server description.
     Description = new AuthorizationServerDescription
                       {
                           AuthorizationEndpoint = new Uri("https://accounts.google.com/o/oauth2/auth"),
                           TokenEndpoint = new Uri("https://accounts.google.com/o/oauth2/token"),
                           ProtocolVersion = ProtocolVersion.V20,
                       };
 }
 private void InitializeWebServerClient()
 {
     var authorizationServerUri = new Uri("http://localhost:11625");
     var authorizationServer = new AuthorizationServerDescription
     {
         AuthorizationEndpoint = new Uri(authorizationServerUri, "/OAuth/Authorize"),
         TokenEndpoint = new Uri(authorizationServerUri, "/OAuth/Token")
     };
     _webServerClient = new WebServerClient(authorizationServer, "123456", "abcdef");
 }
 protected OAuth2AuthorizationProvider(string id, string authorizationEndpoint, string tokenEndpoint, string clientId, string clientSecret)
 {
     Id = id;
     this.clientId = clientId;
     this.clientSecret = clientSecret;
     description = new AuthorizationServerDescription {
         TokenEndpoint = new Uri(tokenEndpoint),
         AuthorizationEndpoint = new Uri(authorizationEndpoint),
         ProtocolVersion = ProtocolVersion.V20
     };
 }
示例#22
0
 public HomeController()
 {
     var a = Guid.NewGuid().ToString("N");
     var authServer = new AuthorizationServerDescription()
     {
         AuthorizationEndpoint = new Uri("http://localhost:4251/OAuth/Authorize"),
         TokenEndpoint = new Uri("http://localhost:4251/OAuth/Token"),
     };
     Client = new UserAgentClient(authServer, "samplewebapiconsumer", "samplesecret");
     Authorization = new AuthorizationState { Callback = new Uri("http://localhost:4494/") };
 }
        static async void MainAsync(string[] args)
        {
            // Ignore SSL cert errors for now
            ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;

            // The description of the authorization server to which we will be connecting. The most important component
            // is the token endpoint, which is the URL at which the server listens for token requests
            var authorizationServerDescription = new AuthorizationServerDescription
            {
                // Must use actual computer name as DotNetOpenAuth will throw exception if the computer name used does not match the server name
                TokenEndpoint = new Uri("https://localhost:44300/api/token"),
                ProtocolVersion = ProtocolVersion.V20
            };

            // Create the client with which we will be connecting to the server.
            var client = new UserAgentClient(authorizationServerDescription, clientIdentifier: "client1", clientSecret: "secret1");
            
            // The scope that we request for the client. Note: this can also be null if we don't want to request any specific 
            // scope or more than one scope if we want to request an access token that is valid for several scopes
            //var scope = new[] { "demo-scope-client-1" };

            // Request a new client access token for the specified scopes (http://tools.ietf.org/html/rfc6749#section-4.4)
            // This method will use the client identifier and client secret used when constructing the UserAgentClient instance
            // NOTE: Must use actual computer name in client AuthorizationServerDescription as DotNetOpenAuth will throw exception if the computer name used does not match the server name
            var result = await client.GetClientAccessTokenAsync(); //scope

            // Output some information about the retrieved client access token
            Console.WriteLine("[RETRIEVED CLIENT ACCESS TOKEN]");
            Console.WriteLine("Access token: {0}", result.AccessToken);
            Console.WriteLine("Expiration time: {0}", result.AccessTokenExpirationUtc);
            Console.WriteLine("Scope: {0}", OAuthUtilities.JoinScopes(result.Scope));

            // Now try to access a resource to validate the bearer token
            var httpClient = new OAuthHttpClient(result.AccessToken)
            {
                // Must use actual computer name as DotNetOpenAuth will throw exception if the computer name used does not match the server na
                BaseAddress = new Uri("https://localhost:44300/api/values")
            };
            Console.WriteLine();
            Console.WriteLine("Calling web api…");
            Console.WriteLine();
            var response = httpClient.GetAsync("").Result;
            if (response.StatusCode==HttpStatusCode.OK)
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            else
                Console.WriteLine(response);
            Console.ReadLine();

            Console.WriteLine("\nPress any key to exit...");
            Console.ReadKey();
        }
示例#24
0
        public HomeController()
        {
            var authServer = new AuthorizationServerDescription
                {
                    AuthorizationEndpoint = new Uri(AuthorizationEndpoint),
                    TokenEndpoint = new Uri(TokenEndpoint),
                };

            Client = new UserAgentClient(authServer, ClientId, ClientSecret);
            Authorization = new AuthorizationState
                {
                    Callback = new Uri(AuthorizationCallback)
                };
        }
示例#25
0
        //private void Save(string date)
        //{
        //    Configuration connectionConfiguration = WebConfigurationManager.OpenWebConfiguration("~");
        //    connectionConfiguration.AppSettings.Settings["access_token"].Value = date;
        //    connectionConfiguration.Save(ConfigurationSaveMode.Modified);
        //    ConfigurationManager.RefreshSection("appSettings");
        //}
        private static IAuthorizationState GetAccessToken()
        {
            var authorizationServer = new AuthorizationServerDescription
            {
                TokenEndpoint = new Uri(ConfigurationManager.AppSettings["Link_AccessToken"]),
                ProtocolVersion = ProtocolVersion.V20

            };
            var client = new WebServerClient(authorizationServer, ConfigurationManager.AppSettings["LinkHost"]);
            client.ClientIdentifier = ConfigurationManager.AppSettings["AppId"];
            client.ClientSecret = ConfigurationManager.AppSettings["AppSecret"];

            var state = client.GetClientAccessToken(null);
            return state;
        }
 protected OAuth2Authenticator(
     AuthorizationServerDescription description,
     Func<string, AuthResult.Data> selector,
     string consumerKey,
     string consumerSecret,
     IEnumerable<string> scope)
 {
     _scope    = scope;
     _selector = selector;
     _client   = new WebServerClient(description)
     {
         ClientIdentifier           = consumerKey,
         ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(consumerSecret),
     };
 }
 public static void Authorize(UserAuthorization authorization, string website, string clientId, string clientSecret, Uri redirectUri, string AuthorizationCode)
 {
     if (_serverDescription == null)
     {
         _serverDescription = new AuthorizationServerDescription
         {
             AuthorizationEndpoint = new Uri(string.Format("{0}/api/oauth2/auth", website)),
             TokenEndpoint = new Uri(string.Format("{0}/api/oauth2/token", website))
         };
     }
     var oAuthClient = new ExternalOAuthClient(_serverDescription, clientId, clientSecret, redirectUri);
     var authorizationState = authorization.AuthorizationState;
     oAuthClient.AuthorizeExternal(ref authorizationState, authorization.RefreshToken, AuthorizationCode);
     authorization.AuthorizationState = authorizationState;
 }
        private static AuthorizationServerDescription GetAuthServerDescription()
        {
            //throw new NotImplementedException();
            var authServerDesc = new AuthorizationServerDescription();

            //authorization endpoint of Hello Paisa for the test platform.
            authServerDesc.AuthorizationEndpoint = new Uri(@"https://test.hellopaisa.com.np/OAuth/Auth");

            //token endpoint for the test environment.
            authServerDesc.TokenEndpoint = new Uri(@"https://test.hellopaisa.com.np/OAuth/Token");
            //protocol version of OAuth
            authServerDesc.ProtocolVersion = ProtocolVersion.V20;
            return authServerDesc;

        }
示例#29
0
		/// <summary>
		/// Initializes the <see cref="authorizationServer"/> field if it has not yet been initialized.
		/// </summary>
		private static void EnsureInitialized() {
			if (authorizationServer == null) {
				lock (InitializerLock) {
					if (authorizationServerDescription == null) {
						authorizationServerDescription = new AuthorizationServerDescription {
							AuthorizationEndpoint = new Uri(Utilities.ApplicationRoot, "OAuth.ashx"),
							TokenEndpoint = new Uri(Utilities.ApplicationRoot, "OAuth.ashx"),
						};
					}

					if (authorizationServer == null) {
						authorizationServer = new AuthorizationServer(new OAuthAuthorizationServer());
					}
				}
			}
		}
示例#30
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var authorizationServer = new AuthorizationServerDescription
            {
                AuthorizationEndpoint = new Uri("http://localhost:18001/Katana.Sandbox.WebServer/Authorize"),
                TokenEndpoint = new Uri("http://localhost:18001/Katana.Sandbox.WebServer/Token")
            };
            _webServerClient = new WebServerClient(authorizationServer, "123456", "abcdef");

            if (string.IsNullOrEmpty(AccessToken.Text))
            {
                var authorizationState = _webServerClient.ProcessUserAuthorization(new HttpRequestWrapper(Request));
                if (authorizationState != null)
                {
                    AccessToken.Text = authorizationState.AccessToken;
                    Page.Form.Action = Request.Path;
                }
            }
        }
示例#31
0
        public Uri GetAuthorizationUri()
        {
            _endPoint = "https://start.exactonline.com";

            _authorization = new AuthorizationState
            {
                Callback = new Uri("http://localhost:19648/home/exoauth2")
            };

            var serverDescription = new AuthorizationServerDescription
            {
                AuthorizationEndpoint = new Uri(string.Format("{0}/api/oauth2/auth", _endPoint)),
                TokenEndpoint = new Uri(string.Format("{0}/api/oauth2/token", _endPoint))
            };

            _oAuthClient = new UserAgentClient(serverDescription, "eb93389b-9532-46ca-9b24-898a38e91c22", "jYzWXVFiE87C");
            _oAuthClient.ClientCredentialApplicator = ClientCredentialApplicator.PostParameter("jYzWXVFiE87C");

            return _oAuthClient.RequestUserAuthorization(_authorization);
        }
示例#32
0
        private IAuthorizationState GetAccessToken(string refresh)
        {
            var authorizationServer = new AuthorizationServerDescription
            {
                TokenEndpoint = new Uri(this.TokenUri),
                ProtocolVersion = ProtocolVersion.V20,
            };

            var client = new UserAgentClient(authorizationServer, this.ClientId, this.ClientSecret);
            IAuthorizationState ostate;
            if (refresh == null)
                ostate = client.GetClientAccessToken(new[] { this.API_EndpointUri });
            else
            {
                ostate = new AuthorizationState(new[] { this.API_EndpointUri });
                ostate.RefreshToken = refresh;
                client.RefreshAuthorization(ostate);
            }
            return ostate;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="UserAgentClient"/> class.
 /// </summary>
 /// <param name="authorizationServer">The token issuer.</param>
 /// <param name="clientIdentifier">The client identifier.</param>
 /// <param name="clientCredentialApplicator">
 /// The tool to use to apply client credentials to authenticated requests to the Authorization Server.
 /// May be <c>null</c> for clients with no secret or other means of authentication.
 /// </param>
 public UserAgentClient(AuthorizationServerDescription authorizationServer, string clientIdentifier, ClientCredentialApplicator clientCredentialApplicator)
     : base(authorizationServer, clientIdentifier, clientCredentialApplicator)
 {
 }
示例#34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WebServerClient"/> class.
 /// </summary>
 /// <param name="authorizationServer">The authorization server.</param>
 /// <param name="clientIdentifier">The client identifier.</param>
 /// <param name="clientSecret">The client secret.</param>
 public WebServerClient(AuthorizationServerDescription authorizationServer, string clientIdentifier = null, string clientSecret = null)
     : this(authorizationServer, clientIdentifier, DefaultSecretApplicator(clientSecret))
 {
 }
示例#35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserAgentClient" /> class.
 /// </summary>
 /// <param name="authorizationServer">The token issuer.</param>
 /// <param name="clientIdentifier">The client identifier.</param>
 /// <param name="clientSecret">The client secret.</param>
 /// <param name="hostFactories">The host factories.</param>
 public UserAgentClient(AuthorizationServerDescription authorizationServer, string clientIdentifier = null, string clientSecret = null, IHostFactories hostFactories = null)
     : this(authorizationServer, clientIdentifier, DefaultSecretApplicator(clientSecret), hostFactories)
 {
 }
示例#36
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UserAgentClient" /> class.
 /// </summary>
 /// <param name="authorizationServer">The token issuer.</param>
 /// <param name="clientIdentifier">The client identifier.</param>
 /// <param name="clientCredentialApplicator">The tool to use to apply client credentials to authenticated requests to the Authorization Server.
 /// May be <c>null</c> for clients with no secret or other means of authentication.</param>
 /// <param name="hostFactories">The host factories.</param>
 public UserAgentClient(AuthorizationServerDescription authorizationServer, string clientIdentifier, ClientCredentialApplicator clientCredentialApplicator, IHostFactories hostFactories = null)
     : base(authorizationServer, clientIdentifier, clientCredentialApplicator, hostFactories)
 {
 }