Skip to content

Commit

Permalink
OAuth: Allow setting a unique provider ID when specifying a custom pa…
Browse files Browse the repository at this point in the history
…rameters
  • Loading branch information
Martchus committed Apr 12, 2021
1 parent 2877eeb commit 3895b26
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/OpenQA/Setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ sub read_config {
token_scope => '',
token_label => '',
nickname_from => '',
unique_name => '',
},
hypnotoad => {
listen => ['http://localhost:9526/'],
Expand Down
9 changes: 6 additions & 3 deletions lib/OpenQA/WebAPI/Auth/OAuth2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ sub auth_setup ($server) {
token_scope => $config->{token_scope},
token_label => $config->{token_label},
nickname_from => $config->{nickname_from},
unique_name => $config->{unique_name},
},
},
);
Expand Down Expand Up @@ -85,10 +86,12 @@ sub auth_login ($controller) {
# Note: Using 403 for consistency
return $controller->render(text => "$err->{code}: $err->{message}", status => 403);
}
my $details = $res->json;
my $user = $controller->schema->resultset('Users')->create_user(
my $details = $res->json;
my $provider_name = $main_config->{provider};
$provider_name = $provider_config->{unique_name} || $provider_name if $provider_name eq 'custom';
my $user = $controller->schema->resultset('Users')->create_user(
$details->{id},
provider => "oauth2\@$main_config->{provider}",
provider => "oauth2\@$provider_name",
nickname => $details->{$provider_config->{nickname_from}},
fullname => $details->{name},
email => $details->{email});
Expand Down
1 change: 1 addition & 0 deletions t/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ subtest 'Test configuration default modes' => sub {
token_scope => '',
token_label => '',
nickname_from => '',
unique_name => '',
},
hypnotoad => {
listen => ['http://localhost:9526/'],
Expand Down

0 comments on commit 3895b26

Please sign in to comment.