aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth/Social.pm21
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm5
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm4
4 files changed, 34 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index b2c001566..b1c795b1e 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -219,7 +219,7 @@ sub get_token : Private {
sub set_oauth_token_data : Private {
my ( $self, $c, $token_data ) = @_;
- foreach (qw/facebook_id twitter_id oidc_id/) {
+ foreach (qw/facebook_id twitter_id oidc_id extra/) {
$token_data->{$_} = $c->session->{oauth}{$_} if $c->session->{oauth}{$_};
}
}
@@ -283,6 +283,11 @@ sub process_login : Private {
$user->facebook_id( $data->{facebook_id} ) if $data->{facebook_id};
$user->twitter_id( $data->{twitter_id} ) if $data->{twitter_id};
$user->add_oidc_id( $data->{oidc_id} ) if $data->{oidc_id};
+ $user->extra({
+ %{ $user->get_extra() },
+ %{ $data->{extra} }
+ }) if $data->{extra};
+
$user->update_or_insert;
$c->authenticate( { $type => $data->{$type}, $ver => 1 }, 'no_password' );
diff --git a/perllib/FixMyStreet/App/Controller/Auth/Social.pm b/perllib/FixMyStreet/App/Controller/Auth/Social.pm
index e0abf5c60..b22ca64b1 100644
--- a/perllib/FixMyStreet/App/Controller/Auth/Social.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth/Social.pm
@@ -233,7 +233,11 @@ sub oidc_callback: Path('/auth/OIDC') : Args(0) {
# There's a chance that a user may have multiple OIDC logins, so build a namespaced uid to prevent collisions
my $uid = join(":", $c->cobrand->moniker, $c->cobrand->feature('oidc_login')->{client_id}, $id_token->payload->{sub});
- $c->forward('oauth_success', [ 'oidc', $uid, $name, $email ]);
+ # The cobrand may want to set values in the user extra field, e.g. a CRM ID
+ # which is passed to Open311 with reports made by this user.
+ my $extra = $c->cobrand->call_hook(oidc_user_extra => $id_token);
+
+ $c->forward('oauth_success', [ 'oidc', $uid, $name, $email, $extra ]);
}
@@ -250,7 +254,7 @@ sub oauth_failure : Private {
}
sub oauth_success : Private {
- my ($self, $c, $type, $uid, $name, $email) = @_;
+ my ($self, $c, $type, $uid, $name, $email, $extra) = @_;
my $user;
if ($email) {
@@ -277,6 +281,12 @@ sub oauth_success : Private {
$user->add_oidc_id($uid);
}
$user->name($name);
+ if ($extra) {
+ $user->extra({
+ %{ $user->get_extra() },
+ %$extra
+ });
+ }
$user->in_storage() ? $user->update : $user->insert;
} else {
# We've got an ID, but no email
@@ -290,11 +300,18 @@ sub oauth_success : Private {
if ($user) {
# Matching ID in our database
$user->name($name);
+ if ($extra) {
+ $user->extra({
+ %{ $user->get_extra() },
+ %$extra
+ });
+ }
$user->update;
} else {
# No matching ID, store ID for use later
$c->session->{oauth}{$type . '_id'} = $uid;
$c->session->{oauth}{name} = $name;
+ $c->session->{oauth}{extra} = $extra;
$c->stash->{oauth_need_email} = 1;
}
}
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index bea2250fd..c6ecea79e 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -1324,6 +1324,11 @@ sub process_confirmation : Private {
$problem->user->$_( $data->{$_} ) if $data->{$_};
}
$problem->user->add_oidc_id($data->{oidc_id}) if $data->{oidc_id};
+ $problem->user->extra({
+ %{ $problem->user->get_extra() },
+ %{ $data->{extra} }
+ }) if $data->{extra};
+
$problem->user->update;
}
if ($problem->user->email_verified) {
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 68c8a41ce..0f3f8c098 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -580,6 +580,10 @@ sub process_confirmation : Private {
$comment->user->$_( $data->{$_} ) if $data->{$_};
}
$comment->user->add_oidc_id($data->{oidc_id}) if $data->{oidc_id};
+ $comment->user->extra({
+ %{ $comment->user->get_extra() },
+ %{ $data->{extra} }
+ }) if $data->{extra};
$comment->user->password( $data->{password}, 1 ) if $data->{password};
$comment->user->update;
}