diff options
author | Loïc Hoguin <[email protected]> | 2016-08-29 12:39:49 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2016-08-29 12:40:03 +0200 |
commit | c807880f7ac73f813b2660ea81a00f7712a4e793 (patch) | |
tree | ba1d09e9b177f230665a80513b33fbd532000ce4 /archives/extend/2014-March/000342.html | |
parent | b1df25a7d9cda697513650659b781b55b40898f8 (diff) | |
download | ninenines.eu-c807880f7ac73f813b2660ea81a00f7712a4e793.tar.gz ninenines.eu-c807880f7ac73f813b2660ea81a00f7712a4e793.tar.bz2 ninenines.eu-c807880f7ac73f813b2660ea81a00f7712a4e793.zip |
Add old mailing list archives
Diffstat (limited to 'archives/extend/2014-March/000342.html')
-rw-r--r-- | archives/extend/2014-March/000342.html | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/archives/extend/2014-March/000342.html b/archives/extend/2014-March/000342.html new file mode 100644 index 00000000..b2779a5d --- /dev/null +++ b/archives/extend/2014-March/000342.html @@ -0,0 +1,129 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<HTML> + <HEAD> + <TITLE> [99s-extend] Cowboy pre request filter + </TITLE> + <LINK REL="Index" HREF="index.html" > + <LINK REL="made" HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Cowboy%20pre%20request%20filter&In-Reply-To=%3CCACE%3DTJqaoxrqsCSnN44s_5x4MabgWBVfaN_pecVrShnUuU-9aQ%40mail.gmail.com%3E"> + <META NAME="robots" CONTENT="index,nofollow"> + <style type="text/css"> + pre { + white-space: pre-wrap; /* css-2.1, curent FF, Opera, Safari */ + } + </style> + <META http-equiv="Content-Type" content="text/html; charset=us-ascii"> + <LINK REL="Previous" HREF="000341.html"> + <LINK REL="Next" HREF="000346.html"> + </HEAD> + <BODY BGCOLOR="#ffffff"> + <H1>[99s-extend] Cowboy pre request filter</H1> + <B>Mark Nijhof</B> + <A HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20Cowboy%20pre%20request%20filter&In-Reply-To=%3CCACE%3DTJqaoxrqsCSnN44s_5x4MabgWBVfaN_pecVrShnUuU-9aQ%40mail.gmail.com%3E" + TITLE="[99s-extend] Cowboy pre request filter">mark.nijhof at cre8ivethought.com + </A><BR> + <I>Thu Mar 6 10:52:01 CET 2014</I> + <P><UL> + <LI>Previous message: <A HREF="000341.html">[99s-extend] Cowboy pre request filter +</A></li> + <LI>Next message: <A HREF="000346.html">[99s-extend] Trying to grok erlang.mk +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#342">[ date ]</a> + <a href="thread.html#342">[ thread ]</a> + <a href="subject.html#342">[ subject ]</a> + <a href="author.html#342">[ author ]</a> + </LI> + </UL> + <HR> +<!--beginarticle--> +<PRE>I also found the answer to my own question: custom middleware + +I just created: + + 1 -module(authentication_middleware). + 2 + 3 -behaviour(cowboy_middleware). + 4 + 5 -export([execute/2]). + 6 + 7 execute(Req, Env) -> + 8 + 9 {Path, Req1} = cowboy_req:path(Req), + 10 + 11 case Path of + 12 <<"/login.html">> -> + 13 {ok, Req1, Env}; + 14 <<"/do_login">> -> + 15 {ok, Req1, Env}; + 16 _ -> + 17 case id3as_security:is_request_authenticated(Req1) of + 18 {error, eauth, Req2} -> + 19 {ok, Req4} = cowboy_req:reply(303, +[{<<"Location">>, <<"/login.html">>}], "", Req2), + 20 {halt, Req4}; + 21 {authenticated, _Id, Req2} -> + 22 {ok, Req2, Env} + 23 end + 24 end. + +And put this between the cowboy_router and cowboy_handler and life is all +good. + +-Mark + + + +On Thu, Mar 6, 2014 at 12:47 AM, Mark Nijhof <<A HREF="https://lists.ninenines.eu/listinfo/extend">mark.nijhof at cre8ivethought.com</A> +><i> wrote: +</I> +><i> Hi, +</I>><i> +</I>><i> I want to create a module that basically sits between the incoming request +</I>><i> and the http handler for that request to ensure a request is authenticated +</I>><i> (using a cookie), if the request is not authenticated then I like to +</I>><i> redirect to a specific login page (which should not be filtered). +</I>><i> +</I>><i> Is this possible with Cowboy? Should I use the onrequest hook (not sure if +</I>><i> I can force redirects from there) for that or is there a better way? +</I>><i> +</I>><i> Cheers, +</I>><i> +</I>><i> -Mark +</I>><i> +</I>><i> -- +</I>><i> Mark Nijhof +</I>><i> t: @MarkNijhof <<A HREF="https://twitter.com/MarkNijhof">https://twitter.com/MarkNijhof</A>> +</I>><i> s: marknijhof +</I>><i> +</I>><i> +</I> + +-- +Mark Nijhof +t: @MarkNijhof <<A HREF="https://twitter.com/MarkNijhof">https://twitter.com/MarkNijhof</A>> +s: marknijhof +-------------- next part -------------- +An HTML attachment was scrubbed... +URL: <<A HREF="http://lists.ninenines.eu/archives/extend/attachments/20140306/24422ef2/attachment.html">http://lists.ninenines.eu/archives/extend/attachments/20140306/24422ef2/attachment.html</A>> +</PRE> + +<!--endarticle--> + <HR> + <P><UL> + <!--threads--> + <LI>Previous message: <A HREF="000341.html">[99s-extend] Cowboy pre request filter +</A></li> + <LI>Next message: <A HREF="000346.html">[99s-extend] Trying to grok erlang.mk +</A></li> + <LI> <B>Messages sorted by:</B> + <a href="date.html#342">[ date ]</a> + <a href="thread.html#342">[ thread ]</a> + <a href="subject.html#342">[ subject ]</a> + <a href="author.html#342">[ author ]</a> + </LI> + </UL> + +<hr> +<a href="https://lists.ninenines.eu/listinfo/extend">More information about the Extend +mailing list</a><br> +</body></html> |