Add basic Persona support

This allows users to sign in to Hydra using Mozilla Persona accounts.
When a user first sign in, a row in the Users table for the given
Persona identity (an email address) is created automatically.

To do: figure out how to deal with legacy accounts.
This commit is contained in:
Eelco Dolstra
2013-07-08 23:54:40 +02:00
parent b46f2134e0
commit c08fc6ce1e
5 changed files with 86 additions and 7 deletions

View File

@ -135,7 +135,7 @@ sub machines :Local Args(0) {
{ order_by => 'stoptime desc', rows => 1 });
${$machines}{$m}{'idle'} = $idle ? $idle->stoptime : 0;
}
$c->stash->{machines} = $machines;
$c->stash->{steps} = [ $c->model('DB::BuildSteps')->search(
{ finished => 0, 'me.busy' => 1, 'build.busy' => 1, },

View File

@ -8,6 +8,8 @@ use Crypt::RandPasswd;
use Digest::SHA1 qw(sha1_hex);
use Hydra::Helper::Nix;
use Hydra::Helper::CatalystUtils;
use LWP::UserAgent;
use JSON;
__PACKAGE__->config->{namespace} = '';
@ -70,6 +72,43 @@ sub logout_GET {
}
sub persona_login :Path('/persona-login') Args(0) {
my ($self, $c) = @_;
$c->stash->{json} = {};
die if $c->request->method ne "POST";
my $assertion = $c->req->params->{assertion} or die;
my $ua = new LWP::UserAgent;
my $response = $ua->post(
'https://verifier.login.persona.org/verify',
{ assertion => $assertion,
audience => "http://localhost:3000/"
});
Catalyst::Exception->throw("Did not get a response from Persona.") unless $response->is_success;
my $d = decode_json($response->decoded_content) or die;
Catalyst::Exception->throw("Persona says: $d->{reason}") if $d->{status} ne "okay";
my $email = $d->{email} or die;
my $user = $c->find_user({ username => $email });
if (!$user) {
$c->model('DB::Users')->create(
{ username => $email
, password => "!"
, emailaddress => $email,
});
$user = $c->find_user({ username => $email }) or die;
}
$c->set_authenticated($user);
$c->stash->{json}->{result} = "ok";
}
sub captcha :Local Args(0) {
my ($self, $c) = @_;
$c->create_captcha();