Esempio n. 1
0
        public void BuildAuthorizationRequestUrlThrowsWithMissingRedirectUrlForTokenFlow()
        {
            OAuth2Config config = new OAuth2Config
            {
                AuthorizeServiceEndpoint = @"https://example.com/authorize",
                ClientId    = "a",
                RedirectUrl = null, // Must exist for token workflow
            };

            Assert.Throws <InvalidParameterException>(() => OAuth2Utils.BuildAuthorizationRequestUrl(config, "state", null));
        }
Esempio n. 2
0
        public void BuildAuthorizationRequestUrlUsesAllParameters()
        {
            OAuth2Config config = new OAuth2Config
            {
                AuthorizeServiceEndpoint = @"https://example.com/authorize",
                ClientId    = "fwser2sewr689f7",
                RedirectUrl = "com.example.myapp://oauth2redirect/",
            };
            string state = "7ysv8L9s4LB9CZpA";
            string url   = OAuth2Utils.BuildAuthorizationRequestUrl(config, state, null);

            Assert.AreEqual(@"https://example.com/authorize?response_type=token&client_id=fwser2sewr689f7&redirect_uri=com.example.myapp%3A%2F%2Foauth2redirect%2F&state=7ysv8L9s4LB9CZpA", url);
        }
Esempio n. 3
0
        public void BuildAuthorizationRequestUrlEscapesParameters()
        {
            OAuth2Config config = new OAuth2Config
            {
                AuthorizeServiceEndpoint = @"https://example.com/authorize",
                ClientId    = "a:a",
                RedirectUrl = "b:b",
            };
            string state = "c:c";
            string url   = OAuth2Utils.BuildAuthorizationRequestUrl(config, state, null);

            Assert.IsTrue(url.Contains("client_id=a%3Aa"));
            Assert.IsTrue(url.Contains("redirect_uri=b%3Ab"));
            Assert.IsTrue(url.Contains("state=c%3Ac"));
        }
Esempio n. 4
0
        public void BuildAuthorizationRequestUrlLeavesOutOptionalParameters()
        {
            OAuth2Config config = new OAuth2Config
            {
                // Scope won't be set
                AuthorizeServiceEndpoint = @"https://example.com/authorize",
                ClientId    = "a",
                RedirectUrl = "b",
                Flow        = AuthorizationFlow.Code,
            };

            // The scope paramter should not be part of the url
            string url = OAuth2Utils.BuildAuthorizationRequestUrl(config, "c", null);

            Assert.IsTrue(!url.Contains("token", StringComparison.InvariantCultureIgnoreCase));
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private static string GetAuthorizationUrl(OAuth2Config authorization)
        {
            //get this value by opening your web app in browser.
            string        RedirectUrl = "http://localhost:54762/Pages/facturacion/FrmCargarXML.aspx";
            string        Url         = authorization.server;
            StringBuilder UrlBuilder  = new StringBuilder(Url);

            UrlBuilder.Append("client_id=" + authorization.clientId);
            UrlBuilder.Append("&username="******"&password="******"&client_secret=" + authorization.clientSecret);
            UrlBuilder.Append("&scope=" + authorization.scope);
            UrlBuilder.Append("&access_type=" + "password");
            UrlBuilder.Append("&redirect_uri=" + RedirectUrl);

            return(UrlBuilder.ToString());
        }
Esempio n. 6
0
        public void BuildAuthorizationRequestUrlUsesCodeVerifier()
        {
            OAuth2Config config = new OAuth2Config
            {
                AuthorizeServiceEndpoint = @"https://example.com/authorize",
                ClientId    = "a",
                RedirectUrl = "b",
                Flow        = AuthorizationFlow.Code,
            };

            // The scope paramter should not be part of the url
            string codeVerifier = "ccc";
            string url          = OAuth2Utils.BuildAuthorizationRequestUrl(config, "c", codeVerifier);

            Assert.IsTrue(url.Contains("code_challenge=", StringComparison.InvariantCultureIgnoreCase));
            Assert.IsTrue(url.Contains("code_challenge_method=S256", StringComparison.InvariantCultureIgnoreCase));
        }
Esempio n. 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            var isBuilder = services.AddIdentityServer();

            if (Environment.IsProduction())
            {
                isBuilder.AddSigningCredential(new X509Certificate2(Path.Combine(Directory.GetCurrentDirectory(),
                                                                                 Configuration["Certificates:Path"]),
                                                                    Configuration["Certificates:Password"]));
            }
            else
            {
                isBuilder.AddDeveloperSigningCredential(); //测试的时候可使用临时的证书
            }

            isBuilder.AddInMemoryClients(OAuth2Config.GetClients(Configuration))
            .AddInMemoryApiResources(OAuth2Config.GetApiResources())
            .AddInMemoryIdentityResources(OAuth2Config.GetIdentityResources())
            .AddResourceOwnerValidator <ResourceOwnerPasswordValidator>()    //User验证接口
            .AddProfileService <ProfileService>();
        }
Esempio n. 8
0
        public static void AuthorizeUser(OAuth2Config authorization)
        {
            string Url = GetAuthorizationUrl(authorization);

            HttpContext.Current.Response.Redirect(Url, false);
        }
Esempio n. 9
0
 public AuthProviderBase(OAuth2Config config)
 {
     _config = config;
 }
Esempio n. 10
0
 public TestClient(OAuth2Config config)
     : base(config)
 {
 }
Esempio n. 11
0
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="httpClient"></param>
 public AuthenticatorService(HttpClient httpClient, OAuth2Config oauthConfig)
 {
     this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
     this.authConfig = oauthConfig ?? throw new ArgumentNullException(nameof(oauthConfig));
 }
Esempio n. 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OAuth2CloudStorageClient"/> class.
 /// </summary>
 /// <param name="config">Sets the <see cref="Config"/> property.</param>
 protected OAuth2CloudStorageClient(OAuth2Config config)
 {
     Config = config;
 }
Esempio n. 13
0
 public LinkedInProvider(OAuth2Config config)
     : base(config)
 {
 }
Esempio n. 14
0
 public OAuth2Service(IOptions <OAuth2Config> configAccessor)
 {
     _config = configAccessor.Value;
 }
Esempio n. 15
0
 public MicrosoftProvider(OAuth2Config config) : base(config)
 {
 }