Compare Revisions

Quick Setup

Revision 421601:

Revision 421601 by sushimako on

Revision 451635:

Revision 451635 by fmarier on

Title:
Quick Setup
Quick Setup
Slug:
Mozilla/Persona/Quick_Setup
Mozilla/Persona/Quick_Setup
Tags:
"Persona"
Persona,
Content:

Revision 421601
Revision 451635
t284      For an example on how to use Persona in a C# ASP.Net MVC3 at284      For examples of how to use Persona in other languages, have
>pplication, <a href="https://github.com/sergiotapia/ASP.Net-MVC3-> a look at the <a href="https://github.com/mozilla/browserid-cook
>Persona-Demo" title="https://github.com/sergiotapia/ASP.Net-MVC3->book" title="https://github.com/mozilla/browserid-cookbook">cookb
>Persona-Demo">visit this application demo</a>&nbsp;or see the Con>ook</a>.
>troller code below: 
285    </p>
286    <p>285    </p>
287      &nbsp;
288    </p>
289    <pre class="brush:java;">
290public class AuthController : Controller
291{
292    [HttpPost]
293    public ActionResult Login(string assertion)
294    {
295        if (assertion == null)
296        {
297            // The 'assertion' key of the API wasn't POSTED. Redi
>rect, 
298            // or whatever you'd like, to try again.
299            return RedirectToAction("Index", "Home");
300        }
301 
302        using (var web = new WebClient())
303        {
304            // Build the data we're going to POST.
305            var data = new NameValueCollection();
306            data["assertion"] = assertion;
307            data["audience"] = "https://example.com:443"; // Use 
>your website's URL here. 
308 
309 
310            // POST the data to the Persona provider (in this cas
>e Mozilla) 
311            var response = web.UploadValues("https://verifier.log
>in.persona.org/verify", "POST", data); 
312            var buffer = Encoding.Convert(Encoding.GetEncoding("i
>so-8859-1"), Encoding.UTF8, response); 
313 
314 
315            // Convert the response to JSON.
316            var tempString = Encoding.UTF8.GetString(buffer, 0, r
>esponse.Length); 
317            var reader = new JsonReader();
318            dynamic output = reader.Read(tempString);
319 
320            if (output.status == "okay")
321            {
322                string email = output.email; // Since this is dyn
>amic, convert it to string. 
323                FormsAuthentication.SetAuthCookie(email, true);
324                return RedirectToAction("Index", "Home");
325            }
326 
327            // Could not log in, do something else.
328            return RedirectToAction("Index", "Home");
329        }
330    }
331}
332</pre>

Back to History