public void TestAuth2() { string realm = "myrealm"; string userName = "******"; string password = "******"; DigestAuthentication auth = new DigestAuthentication(OnAuth2, null); string server = auth.CreateResponse(realm); NameValueCollection args = Decode(server); string cnonce = "a773bd8"; string response = CreateResponse(userName, realm, password, args["nonce"], cnonce, args["qop"]); string client = string.Format( "Digest username=\"{6}\", realm=\"{5}\", nonce={0}, uri=\"{1}\", qop=auth, nc=00000001, cnonce=\"{2}\", response=\"{3}\", opaque=\"{4}\"", args["nonce"], "/membersonly/", cnonce, response, args["opaque"], realm, userName); object obj = auth.Authenticate(client, realm, "GET"); Assert.NotNull(obj); Assert.Equal("hello", (string)obj); }
private static AppFunc EnableAuthentication(AppFunc app, string password) { return(DigestAuthentication.Enable( app, (env) => { var request = new OwinRequest(env); if (request.CanAccept) { return false; } if (!request.Path.StartsWith("/backgrounds/")) { return true; } if (request.Path.EndsWith("/list") || request.Path.EndsWith("/listall")) { return true; } return false; // all other requests to /backgrounds/ without /list(all) }, "WordsLive", (user) => (user == "WordsLive" ? new DigestAuthentication.UserPassword { Password = password } : (DigestAuthentication.UserPassword?)null) )); }
public void TestDecoderFailure() { Assert.Null(DigestAuthentication.Decode("NoDigest", Encoding.ASCII)); NameValueCollection col = DigestAuthentication.Decode("Digest \x5real=\"\"", Encoding.ASCII); Assert.Null(col); }
public void TestResponse() { DigestAuthentication digest = new DigestAuthentication(OnTestAuth, null); string response = digest.CreateResponse("blaj", false); Assert.Equal("Digest ", response.Substring(0, 7)); NameValueCollection parts = Decode(response); Assert.NotNull(parts["realm"]); Assert.NotNull(parts["qop"]); Assert.NotNull(parts["nonce"]); Assert.NotNull(parts["opaque"]); Assert.Equal("blaj", parts["realm"]); }
public IAuthenticator GetAuthenticator(ProviderType provider) { IAuthenticator auth; string authenticationType = _config["bop.config.auth.type"]; if ("digest".Equals(authenticationType)) { string username = _config["bop.config.auth.username"]; string password = _config["bop.config.auth.password"]; auth = new DigestAuthentication(username, password); } else { auth = null; } return(auth); }
public void TestAuth() { DigestAuthentication auth = new DigestAuthentication(OnTestAuth, null); object res = auth.Authenticate( @"Digest username=""Mufasa"", realm=""*****@*****.**"", nonce=""dcd98b7102dd2f0e8b11d0f600bfb0c093"", uri=""/dir/index.html"", qop=auth, nc=00000001, cnonce=""0a4f113b"", response=""6629fae49393a05397450978507c4ef1"", opaque=""5ccc069c403ebaf9f0171e9517f40e41"" ", "*****@*****.**", "GET", false); Assert.NotNull(res); Assert.Equal("testobj", (string)res); }
public void TestDecoder() { NameValueCollection col = DigestAuthentication.Decode(@"Digest username=""Mufasa"", realm=""*****@*****.**"", nonce=""dcd98b7102dd2f0e8b11d0f600bfb0c093"", uri=""/dir/index.html"", qop=auth, nc=00000001, cnonce=""0a4f113b"", response=""6629fae49393a05397450978507c4ef1"", opaque=""5ccc069c403ebaf9f0171e9517f40e41"" ", Encoding.ASCII); Assert.Equal("*****@*****.**", col["realm"]); Assert.Equal("dcd98b7102dd2f0e8b11d0f600bfb0c093", col["nonce"]); Assert.Equal("/dir/index.html", col["uri"]); Assert.Equal("auth", col["qop"]); Assert.Equal("00000001", col["nc"]); Assert.Equal("0a4f113b", col["cnonce"]); Assert.Equal("6629fae49393a05397450978507c4ef1", col["response"]); Assert.Equal("5ccc069c403ebaf9f0171e9517f40e41", col["opaque"]); }
private static bool TryToAuthenticate(HttpRequestMessage request, int portalId) { if (request?.Headers.Authorization == null) { return(false); } string authHeader = request?.Headers.Authorization.ToString(); var digestAuthentication = new DigestAuthentication(new DigestAuthenticationRequest(authHeader, request.Method.Method), portalId, request.GetIPAddress()); if (digestAuthentication.IsValid) { SetCurrentPrincipal(digestAuthentication.User, request); } else if (digestAuthentication.IsNonceStale) { return(true); } return(false); }
public void StartTutorial() { _server = new HttpServer.HttpServer(); // Let's use Digest authentication which is superior to basic auth since it // never sends password in clear text. DigestAuthentication auth = new DigestAuthentication(OnAuthenticate, OnAuthenticationRequired); _server.AuthenticationModules.Add(auth); // simple example of an regexp redirect rule. Go to http://localhost:8081/profile/arne to get redirected. _server.Add(new RegexRedirectRule("/profile/(?<first>[a-zA-Z0-9]+)", "/user/view/${first}")); // Let's reuse our module from previous tutorial to handle pages. _server.Add(new Tutorial3.MyModule()); // and start the server. _server.Start(IPAddress.Any, 8081); Console.WriteLine("Goto http://localhost:8081/membersonly to get authenticated."); Console.WriteLine("Password is 'morsOlle', and userName is 'arne'"); }