Skip to content

Commit

Permalink
[Highways England] Initialise single-sign on
Browse files Browse the repository at this point in the history
Initial setup for single sign on
  • Loading branch information
MorayMySoc committed Aug 15, 2024
1 parent 2460d7d commit eb85622
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion perllib/FixMyStreet/App/Controller/Auth/Social.pm
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ sub oidc_callback: Path('/auth/OIDC') : Args(0) {
$c->log->info("Social::oidc_callback no id_token: " . $oidc->{last_response}->{_content});
$c->detach('oauth_failure');
}

my $message = '';
for my $key (sort keys %{$id_token->payload}) {
$message .= $key . " : " . $id_token->payload->{$key} . "\n" if $id_token->payload->{$key};
}
$c->log->debug($message) if $message;
# sanity check the token audience is us...
unless ($id_token->payload->{aud} eq $c->forward('oidc_config')->{client_id}) {
$c->log->info("Social::oidc_callback invalid id_token: expected aud to be " . $c->forward('oidc_config')->{client_id} . " but it was " . $id_token->payload->{aud});
Expand Down
29 changes: 29 additions & 0 deletions perllib/FixMyStreet/Cobrand/HighwaysEngland.pm
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,35 @@ sub _redact {
return $s;
}

=head1 OIDC single sign on
Noational Highways has a single-sign on option
=over 4
=item * Single sign on is enabled if the configuration is set up
=cut

sub social_auth_enabled {
my $self = shift;

return $self->feature('oidc_login') ? 1 : 0;
}

=item * Different single sign-ons send user details differently, user_from_oidc extracts the relevant parts
=cut

sub user_from_oidc {
my ($self, $payload) = @_;

Check warning on line 218 in perllib/FixMyStreet/Cobrand/HighwaysEngland.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/HighwaysEngland.pm#L218

Added line #L218 was not covered by tests

my $name = join(" ", $payload->{given_name}, $payload->{family_name});

Check warning on line 220 in perllib/FixMyStreet/Cobrand/HighwaysEngland.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/HighwaysEngland.pm#L220

Added line #L220 was not covered by tests
my $email = $payload->{email} ? lc($payload->{email}) : '';

return ($name, $email);

Check warning on line 223 in perllib/FixMyStreet/Cobrand/HighwaysEngland.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/HighwaysEngland.pm#L223

Added line #L223 was not covered by tests
}

sub munge_report_new_bodies {
my ($self, $bodies) = @_;
# On the cobrand there is only the HE body
Expand Down

0 comments on commit eb85622

Please sign in to comment.