public void GetProviderMetadata()
        {
            string             hostname = GetBaseUrl("/");
            OpenIdRelyingParty rp       = new OpenIdRelyingParty();

            providerMetadata = rp.ObtainProviderInformation(hostname);
        }
Beispiel #2
0
        public void Obtain_Provider_Information()
        {
            // given
            rpid   = "rp-discovery-openid_configuration";
            claims = "normal";
            string             hostname = GetBaseUrl("/");
            OpenIdRelyingParty rp       = new OpenIdRelyingParty();

            // when
            OIDCProviderMetadata response = rp.ObtainProviderInformation(hostname);

            // then
            response.validate();
        }
Beispiel #3
0
        public void Reject_Wrong_Discovered_Issuer()
        {
            // given
            rpid   = "rp-discovery-issuer_not_matching_config";
            claims = "_";
            string             hostname = GetBaseUrl("/");
            string             userid   = "https://rp.certification.openid.net:8080/" + rpid;
            OpenIdRelyingParty rp       = new OpenIdRelyingParty();
            string             issuer   = rp.ObtainIssuerFromURL(userid, baseurl.ToString());

            // when
            OIDCProviderMetadata response = rp.ObtainProviderInformation(hostname, issuer);

            // then
        }
Beispiel #4
0
        public void Can_Discover_OpenID_Providers_With_JWKS_Json()
        {
            // given
            rpid   = "rp-discovery-jwks_uri_keys";
            claims = "normal";
            string             hostname = GetBaseUrl("/");
            OpenIdRelyingParty rp       = new OpenIdRelyingParty();

            // when
            OIDCProviderMetadata response = rp.ObtainProviderInformation(hostname);

            // then
            response.validate();
            Assert.NotNull(response.JwksUri);
            Assert.NotNull(response.Keys);
            Assert.Greater(response.Keys.Count, 0);
        }
Beispiel #5
0
        public void Should_Wrong_Discovered_Issuer_Be_Rejected()
        {
            rpid = "rp-discovery-issuer_not_matching_config";

            // given
            string             hostname = GetBaseUrl("/");
            string             userid   = "https://" + opBaseurl.Host + ":" + opBaseurl.Port + "/" + rpid;
            OpenIdRelyingParty rp       = new OpenIdRelyingParty();
            string             issuer   = rp.ObtainIssuerFromURL(userid, opBaseurl.ToString());

            issuer = issuer.Replace("localhost", "wrong.hostname");

            // when
            rp.ObtainProviderInformation(hostname, issuer);

            // then
        }
Beispiel #6
0
        public void Should_Obtain_Provider_Information_With_JWKS_Json()
        {
            rpid = "rp-discovery-jwks_uri_keys";

            // given
            string             hostname = GetBaseUrl("/");
            OpenIdRelyingParty rp       = new OpenIdRelyingParty();

            // when
            OIDCProviderMetadata response = rp.ObtainProviderInformation(hostname);

            // then
            response.Validate();

            Assert.IsNotNull(response.Keys);
            Assert.Greater(response.Keys.Count, 0);
        }
        public void Should_Use_Distributed_Claims()
        {
            rpid = "rp-claims-distributed";
            claims = "distributed";

            // given
            OpenIdRelyingParty rp = new OpenIdRelyingParty();
            string hostname = GetBaseUrl("/");
            providerMetadata = rp.ObtainProviderInformation(hostname);

            OIDCAuthCodeResponseMessage authResponse = GetAuthResponse(ResponseType.Code, null, true) as OIDCAuthCodeResponseMessage;
            OIDCTokenResponseMessage tokenResponse = GetToken(authResponse);
            OIDCUserInfoRequestMessage userInfoRequestMessage = new OIDCUserInfoRequestMessage();

            // when
            OIDCUserInfoResponseMessage userInfoResponse = GetUserInfo(authResponse.Scope, authResponse.State, tokenResponse.AccessToken);

            // then
            Assert.NotNull(userInfoResponse);
            Assert.AreEqual(userInfoResponse.CustomClaims["age"], 30);
        }
        private void LoadOPInformation(OpenIDProviderElement opEntry)
        {
            Sign    = opEntry.Sign;
            Encrypt = opEntry.Encrypt;

            if (!String.IsNullOrEmpty(opEntry.OPIssuer))
            {
                OpenIdRelyingParty rp = new OpenIdRelyingParty();
                ProviderMatadata = rp.ObtainProviderInformation(opEntry.OPIssuer, opEntry.OPIssuer);
            }
            else
            {
                foreach (string value in new List <string>()
                {
                    opEntry.AuthorizationEndpoint, opEntry.TokenEndpoint, opEntry.UserinfoEndpoint
                })
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        throw new ArgumentException("Missign one requred value for configuration. When configuring rp without isser discovery, all these fields must be specified: authorizationEndpoint, tokenEndpoint, userinfoEndpoint.");
                    }
                }

                ProviderMatadata = new OIDCProviderMetadata()
                {
                    AuthorizationEndpoint = opEntry.AuthorizationEndpoint,
                    TokenEndpoint         = opEntry.TokenEndpoint,
                    UserinfoEndpoint      = opEntry.UserinfoEndpoint,
                };

                if (!string.IsNullOrEmpty(opEntry.RegistrationEndpoint))
                {
                    ProviderMatadata.RegistrationEndpoint = opEntry.RegistrationEndpoint;
                }
            }
        }
        private void LoadOPInformation(OpenIDProviderElement opEntry)
        {
            Sign = opEntry.Sign;
            Encrypt = opEntry.Encrypt;

            if (!String.IsNullOrEmpty(opEntry.OPIssuer))
            {
                OpenIdRelyingParty rp = new OpenIdRelyingParty();
                ProviderMatadata = rp.ObtainProviderInformation(opEntry.OPIssuer, opEntry.OPIssuer);
            }
            else
            {
                foreach (string value in new List<string>() { opEntry.AuthorizationEndpoint, opEntry.TokenEndpoint, opEntry.UserinfoEndpoint })
                {
                    if (string.IsNullOrEmpty(value))
                    {
                        throw new ArgumentException("Missign one requred value for configuration. When configuring rp without isser discovery, all these fields must be specified: authorizationEndpoint, tokenEndpoint, userinfoEndpoint.");
                    }
                }

                ProviderMatadata = new OIDCProviderMetadata()
                {
                    AuthorizationEndpoint = opEntry.AuthorizationEndpoint,
                    TokenEndpoint = opEntry.TokenEndpoint,
                    UserinfoEndpoint = opEntry.UserinfoEndpoint,
                };

                if (!string.IsNullOrEmpty(opEntry.RegistrationEndpoint))
                {
                    ProviderMatadata.RegistrationEndpoint = opEntry.RegistrationEndpoint;
                }
            }
        }