コード例 #1
0
		public SecuritySettings Build(IDictionary<string, object> dynamicRaml)
		{
			var settings = new SecuritySettings();
			settings.RequestTokenUri = dynamicRaml.ContainsKey("requestTokenUri")
				? (string) dynamicRaml["requestTokenUri"]
				: null;

			settings.TokenCredentialsUri = dynamicRaml.ContainsKey("tokenCredentialsUri")
				? (string) dynamicRaml["tokenCredentialsUri"]
				: null;

			settings.AuthorizationUri = dynamicRaml.ContainsKey("authorizationUri")
				? (string) dynamicRaml["authorizationUri"]
				: null;

			settings.AccessTokenUri = dynamicRaml.ContainsKey("accessTokenUri") ? (string) dynamicRaml["accessTokenUri"] : null;

			settings.AuthorizationGrants = dynamicRaml.ContainsKey("authorizationGrants")
				? ((object[]) dynamicRaml["authorizationGrants"]).Cast<string>().ToArray()
				: new string[0];

			settings.Scopes = dynamicRaml.ContainsKey("scopes")
				? ((object[]) dynamicRaml["scopes"]).Cast<string>().ToArray()
				: new string[0];

			return settings;
		}
コード例 #2
0
		public void UseOAuth1(string authorizationUri, string requestTokenUri, string tokenCredentialsUri, SecuritySchemeDescriptor securitySchemeDescriptor)
		{
			securityType = "oauth_1_0";
			var securitySettings = new SecuritySettings
			                       {
				                       AuthorizationUri = authorizationUri,
				                       RequestTokenUri = requestTokenUri,
				                       TokenCredentialsUri = tokenCredentialsUri
			                       };
			securityScheme = new SecurityScheme
			                 {
				                 DescribedBy = securitySchemeDescriptor,
				                 Settings = securitySettings,
				                 Type = new Dictionary<string, IDictionary<string, string>> {{"OAuth 1.0", null}}
			                 };
		}
コード例 #3
0
		public void UseOAuth2(string authorizationUri, string accessTokenUri, IEnumerable<string> authorizationGrants, IEnumerable<string> scopes, SecuritySchemeDescriptor securitySchemeDescriptor)
		{
			securityType = "oauth_2_0";
			var securitySettings = new SecuritySettings
			                       {
				                       AuthorizationUri = authorizationUri,
				                       AccessTokenUri = accessTokenUri,
				                       AuthorizationGrants = authorizationGrants,
				                       Scopes = scopes
			                       };
			securityScheme = new SecurityScheme
			                 {
				                 DescribedBy = securitySchemeDescriptor,
				                 Settings = securitySettings,
				                 Type = new Dictionary<string, IDictionary<string, string>> {{"OAuth 2.0", null}}
			                 };
		}
コード例 #4
0
	    private void SerializeSecuritySettings(StringBuilder sb, SecuritySettings settings, int indent)
		{
			if(settings == null)
				return;

			sb.AppendLine("settings:".Indent(indent));
			SerializeProperty(sb, "accessTokenUri", settings.AccessTokenUri, indent + 2);
			SerializeProperty(sb, "authorizationUri", settings.AuthorizationUri, indent + 2);
			SerializeProperty(sb, "requestTokenUri", settings.RequestTokenUri, indent + 2);
			SerializeProperty(sb, "tokenCredentialsUri", settings.TokenCredentialsUri, indent + 2);
			SerializeArrayProperty(sb, "authorizationGrants", settings.AuthorizationGrants, indent + 2);
			SerializeListProperty(sb, "scopes", settings.Scopes, indent + 2);
		}