Esempio n. 1
0
		public bool Authorize(HttpContext httpContext, BasicAuthIdentity identity, string roles)
		{
			if (identity == null)
				return false;

			return identity.Username == identity.Password;
		}
Esempio n. 2
0
		public BasicAuthIdentity GetBasicAuth(HttpRequest request)
		{
			BasicAuthIdentity identity = null;
			var headerValue = request.Headers["Authorization"];
			if (!String.IsNullOrEmpty(headerValue))
			{
				var headerValues = headerValue.Split(' ');
				var scheme = headerValues[0];
				if (string.Compare(scheme, "Basic", true) == 0)
				{
					var encodedUsernameAndPassword = headerValues[1];
					
					var usernameAndPassword = Encoding.UTF8.GetString(Convert.FromBase64String(encodedUsernameAndPassword));
					if (usernameAndPassword != null && usernameAndPassword != ":")
					{
						var tokens = usernameAndPassword.Split(':');
						switch (tokens.Length)
						{
							case 2:
								identity = new BasicAuthIdentity(tokens[0], tokens[1]);
								break;
							case 1:
								identity = new BasicAuthIdentity(tokens[0], null);
								break;
							default:
								identity = null;
								break;
						}
					}
				}
			}

			return identity;
		}