Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Writing authentication behaviour

Received: by 10.216.235.32 with SMTP id t32mr1334708weq.7.1343938260814;
        Thu, 02 Aug 2012 13:11:00 -0700 (PDT)
X-BeenThere: fubumvc-devel@googlegroups.com
Received: by 10.180.103.170 with SMTP id fx10ls128392wib.0.canary; Thu, 02 Aug
 2012 13:10:59 -0700 (PDT)
Received: by 10.180.24.135 with SMTP id u7mr504876wif.3.1343938259127;
        Thu, 02 Aug 2012 13:10:59 -0700 (PDT)
Received: by 10.180.24.135 with SMTP id u7mr504875wif.3.1343938259106;
        Thu, 02 Aug 2012 13:10:59 -0700 (PDT)
Return-Path: <gary.l.co...@gmail.com>
Received: from mail-wg0-f53.google.com (mail-wg0-f53.google.com [74.125.82.53])
        by gmr-mx.google.com with ESMTPS id fb20si4318343wid.3.2012.08.02.13.10.59
        (version=TLSv1/SSLv3 cipher=OTHER);
        Thu, 02 Aug 2012 13:10:59 -0700 (PDT)
Received-SPF: pass (google.com: domain of gary.l.co...@gmail.com designates 74.125.82.53 as permitted sender) client-ip=74.125.82.53;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of gary.l.co...@gmail.com designates 74.125.82.53 as permitted sender) smtp.mail=gary.l.co...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-wg0-f53.google.com with SMTP id fm10so9934383wgb.34
        for <fubumvc-devel@googlegroups.com>; Thu, 02 Aug 2012 13:10:59 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :content-type;
        bh=XKFbOPVo6tUktgpyI+lopIWYAKFfCyJA40wWqJJJEKs=;
        b=yDiaozuZ3FIiLIFN0KWb2tNas9qyNoFpm7wdhPEXH3WfFaNVWNV31E8B2NQQy536Vv
         GJYm2YEck8pcLGcdWAlAaQYp9Wu+TV0zud2ghzLAv0M4G9d0FJz5b0a+sM6qBnkApmL7
         zG9DEx8baqStFX+WnVU3z6KbIvm4KoEIFZAMrKXaD3rBailDCTQ/HLg8UDSDdcyhBjPz
         k7qD251MYTQlEZz07eMpzrCnWD9PUeb0r88z4wS/anWKf8nGHI/amRQ3HFTYeDAoyx2Q
         d44zHOxd7tzxnt0FgBTrI6t3/XUXVDyn9YTvLtW3cWeO+3J41/mDfn+W3kzh2ZgRievu
         hRCw==
MIME-Version: 1.0
Received: by 10.180.78.4 with SMTP id x4mr7326820wiw.19.1343938258908; Thu, 02
 Aug 2012 13:10:58 -0700 (PDT)
Received: by 10.216.236.143 with HTTP; Thu, 2 Aug 2012 13:10:58 -0700 (PDT)
In-Reply-To: <511980f0-800b-4b95-ad4e-efcada8693cc@googlegroups.com>
References: <511980f0-800b-4b95-ad4e-efcada8693cc@googlegroups.com>
Date: Thu, 2 Aug 2012 15:10:58 -0500
Message-ID: <CAO8kZ_Wtj8cyJFUL34aqeD-FmFNkMZV4Y4=6hS9aN=K+dGO...@mail.gmail.com>
Subject: Re: [fubumvc] Writing authentication behaviour
From: Gary Cox <gary.l.co...@gmail.com>
To: fubumvc-devel@googlegroups.com
Content-Type: multipart/alternative; boundary=f46d043bdf5e85b61404c64e02f2

--f46d043bdf5e85b61404c64e02f2
Content-Type: text/plain; charset=ISO-8859-1

We have on our login model a property of type string named ReturnUrl.  Fubu
will wire this up when the login is loaded as long as there is a ReturnUrl
in the querystring.  From there, on successful login we check if ReturnUrl
is empty, if it is we redirect them to the home page, otherwise we redirect
them to the ReturnUrl.

public FubuContinuation Execute(SignInModel model)
        {
            var loggedin = _authenticationService.SignIn(model.UserName,
model.Password, true);

            if (loggedin)
            {
                return
FubuContinuation.RedirectTo(model.ReturnUrl.IsEmpty() ?
_urlRegistry.UrlFor<SomeHomeRequest>() : model.ReturnUrl);
            }

            return FubuContinuation.TransferTo(new SignInRequest {
ReturnUrl = model.ReturnUrl, LoginFailed = true });
        }



On Thu, Aug 2, 2012 at 3:05 PM, gleb Chermennov <thebitteren...@gmail.com>wrote:

> I'm new to the framework and I'm trying to make custom authentication
> logic work in my app.
> Here's the scenario - if a user hits a url and he hasn't been
> authenticated yet, he's being redirected to the login screen. Nothing fancy
> here. But after he successfully authenticated, I want to redirect him to
> the page he intended to visit originally.
> e.g. user tries to reach /posts/edit/1, he's redirected to the login
> screen. after he's logged in, I want the app to automagically redirect him
> to /posts/edit/1.
> I get the part about redirecting to login screen working thanks to Rex
> Morgan's post. Now, how can I redirect user to the original url?
> Here's my behaviour for doing this:
>     public class AuthenticationRequiredBehaviour: BasicBehavior
>     {
>         private readonly ISecurityContext securityContext;
>         private readonly IUrlRegistry urlRegistry;
>         private readonly IOutputWriter outputWriter;
>
>         public AuthenticationRequiredBehaviour(ISecurityContext
> securityContext, IUrlRegistry urlRegistry, IOutputWriter outputWriter):
>             base(PartialBehavior.Ignored)
>         {
>             this.securityContext = securityContext;
>             this.urlRegistry = urlRegistry;
>             this.outputWriter = outputWriter;
>         }
>
>         protected override DoNext performInvoke()
>         {
>             if (securityContext.IsAuthenticated())
>             {
>                 return DoNext.Continue;
>             }
>             var url = urlRegistry.UrlFor<LoginOutputModel>();
>             outputWriter.RedirectToUrl(url);
>             return DoNext.Stop;
>         }
>     }
> and a convention to apply it to particular actions/handlers/endpoints:
>     public class AuthenticationConvention: IConfigurationAction
>     {
>         public void Configure(BehaviorGraph graph)
>         {
>             graph
>                 .Actions()
>                 .Where(c => c.HasAttribute<SecureAttribute>())
>                 .Each(c => c.WrapWith<AuthenticationRequiredBehaviour>());
>         }
>     }
> My guess is I need to wrap Login action with behaviour that will look up
> the previous url (the one hit before the login screen) and do a redirect.
> Is this the right direction or am I completely off here?
>
> --
> You received this message because you are subscribed to the Google Groups
> "FubuMVC Development Group" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/fubumvc-devel/-/L5BEIqfs9bUJ.
> To post to this group, send email to fubumvc-devel@googlegroups.com.
> To unsubscribe from this group, send email to
> fubumvc-devel+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/fubumvc-devel?hl=en.
>



-- 
Thank you,
Gary Cox

--f46d043bdf5e85b61404c64e02f2
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

We have on our login model a property of type string named ReturnUrl. =A0Fu=
bu will wire this up when the login is loaded as long as there is a ReturnU=
rl in the querystring. =A0From there, on successful login we check if Retur=
nUrl is empty, if it is we redirect them to the home page, otherwise we red=
irect them to the ReturnUrl.<div>
<br></div><div><div>public FubuContinuation Execute(SignInModel model)</div=
><div>=A0 =A0 =A0 =A0 {</div><div>=A0 =A0 =A0 =A0 =A0 =A0 var loggedin =3D =
_authenticationService.SignIn(model.UserName, model.Password, true);</div><=
div><br></div><div>
=A0 =A0 =A0 =A0 =A0 =A0 if (loggedin)</div><div>=A0 =A0 =A0 =A0 =A0 =A0 {</=
div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return FubuContinuation.RedirectTo=
(model.ReturnUrl.IsEmpty() ? _urlRegistry.UrlFor&lt;SomeHomeRequest&gt;() :=
 model.ReturnUrl);</div><div>=A0 =A0 =A0 =A0 =A0 =A0 }</div>
<div><br></div><div>=A0 =A0 =A0 =A0 =A0 =A0 return FubuContinuation.Transfe=
rTo(new SignInRequest { ReturnUrl =3D model.ReturnUrl, LoginFailed =3D true=
 });</div><div>=A0 =A0 =A0 =A0 }</div><div><br></div><div><br><br><div clas=
s=3D"gmail_quote">On Thu, Aug 2, 2012 at 3:05 PM, gleb Chermennov <span dir=
=3D"ltr">&lt;<a href=3D"mailto:thebitteren...@gmail.com" target=3D"_blank">=
thebitteren...@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">I&#39;m new to the framework and I&#39;m try=
ing to make custom authentication logic work in my app.<div>Here&#39;s the =
scenario - if a user hits a url and he hasn&#39;t been authenticated yet, h=
e&#39;s being redirected to the login screen. Nothing fancy here. But after=
 he successfully authenticated, I want to redirect him to the page he inten=
ded to visit originally.=A0</div>
<div>e.g. user tries to reach /posts/edit/1, he&#39;s redirected to the log=
in screen. after he&#39;s logged in, I want the app to automagically redire=
ct him to /posts/edit/1.=A0</div><div>I get the part about redirecting to l=
ogin screen working thanks to Rex Morgan&#39;s post. Now, how can I redirec=
t user to the original url?</div>
<div>Here&#39;s my behaviour for doing this:</div><div><div>=A0 =A0 public =
class AuthenticationRequiredBehaviour: BasicBehavior</div><div>=A0 =A0 {</d=
iv><div>=A0 =A0 =A0 =A0 private readonly ISecurityContext securityContext;<=
/div><div>=A0 =A0 =A0 =A0 private readonly IUrlRegistry urlRegistry;</div>
<div>=A0 =A0 =A0 =A0 private readonly IOutputWriter outputWriter;</div><div=
><br></div><div>=A0 =A0 =A0 =A0 public AuthenticationRequiredBehaviour(ISec=
urityContext securityContext, IUrlRegistry urlRegistry, IOutputWriter outpu=
tWriter):=A0</div>
<div>=A0 =A0 =A0 =A0 =A0 =A0 base(PartialBehavior.Ignored)</div><div>=A0 =
=A0 =A0 =A0 {</div><div>=A0 =A0 =A0 =A0 =A0 =A0 this.securityContext =3D se=
curityContext;</div><div>=A0 =A0 =A0 =A0 =A0 =A0 this.urlRegistry =3D urlRe=
gistry;</div><div>=A0 =A0 =A0 =A0 =A0 =A0 this.outputWriter =3D outputWrite=
r;</div>
<div>=A0 =A0 =A0 =A0 }</div><div><br></div><div>=A0 =A0 =A0 =A0 protected o=
verride DoNext performInvoke()</div><div>=A0 =A0 =A0 =A0 {</div><div>=A0 =
=A0 =A0 =A0 =A0 =A0 if (securityContext.IsAuthenticated())</div><div>=A0 =
=A0 =A0 =A0 =A0 =A0 {</div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return DoNe=
xt.Continue;</div>
<div>=A0 =A0 =A0 =A0 =A0 =A0 }</div><div>=A0 =A0 =A0 =A0 =A0 =A0 var url =
=3D urlRegistry.UrlFor&lt;LoginOutputModel&gt;();</div><div>=A0 =A0 =A0 =A0=
 =A0 =A0 outputWriter.RedirectToUrl(url);</div><div>=A0 =A0 =A0 =A0 =A0 =A0=
 return DoNext.Stop;</div><div>=A0 =A0 =A0 =A0 }</div><div>
=A0 =A0 }</div></div><div>and a convention to apply it to particular action=
s/handlers/endpoints:</div><div><div>=A0 =A0 public class AuthenticationCon=
vention: IConfigurationAction</div><div>=A0 =A0 {</div><div>=A0 =A0 =A0 =A0=
 public void Configure(BehaviorGraph graph)</div>
<div>=A0 =A0 =A0 =A0 {</div><div>=A0 =A0 =A0 =A0 =A0 =A0 graph</div><div>=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Actions()</div><div>=A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 .Where(c =3D&gt; c.HasAttribute&lt;SecureAttribute&gt;())</div>=
<div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 .Each(c =3D&gt; c.WrapWith&lt;Authenti=
cationRequiredBehaviour&gt;());</div>
<div>=A0 =A0 =A0 =A0 }</div><div>=A0 =A0 }</div></div><div>My guess is I ne=
ed to wrap Login action with behaviour that will look up the previous url (=
the one hit before the login screen) and do a redirect. Is this the right d=
irection or am I completely off here?</div>
<span class=3D"HOEnZb"><font color=3D"#888888">

<p></p>

-- <br>
You received this message because you are subscribed to the Google Groups &=
quot;FubuMVC Development Group&quot; group.<br>
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msg/fubumvc-devel/-/L5BEIqfs9bUJ" target=3D"_blank">https://groups.goo=
gle.com/d/msg/fubumvc-devel/-/L5BEIqfs9bUJ</a>.<br>=20
To post to this group, send email to <a href=3D"mailto:fubumvc-devel@google=
groups.com" target=3D"_blank">fubumvc-devel@googlegroups.com</a>.<br>
To unsubscribe from this group, send email to <a href=3D"mailto:fubumvc-dev=
el%2Bunsubscribe@googlegroups.com" target=3D"_blank">fubumvc-devel+unsubscr=
ibe@googlegroups.com</a>.<br>

For more options, visit this group at <a href=3D"http://groups.google.com/g=
roup/fubumvc-devel?hl=3Den" target=3D"_blank">http://groups.google.com/grou=
p/fubumvc-devel?hl=3Den</a>.<br>


</font></span></blockquote></div><br><br clear=3D"all"><div><br></div>-- <b=
r>Thank you,<br>Gary Cox<br>
</div></div>

--f46d043bdf5e85b61404c64e02f2--