-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package Ravada::Auth::OpenID; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Data::Dumper; | ||
use Authen::ModAuthPubTkt; | ||
use URI::Escape; | ||
use LWP::UserAgent; | ||
|
||
=head1 NAME | ||
Ravada::Auth::SSO - SSO library for Ravada | ||
=cut | ||
|
||
use Moose; | ||
|
||
no warnings "experimental::signatures"; | ||
use feature qw(signatures state); | ||
|
||
use Ravada::Auth::SQL; | ||
|
||
with 'Ravada::Auth::User'; | ||
|
||
our $CONFIG = \$Ravada::CONFIG; | ||
our $ERR; | ||
|
||
sub BUILD { | ||
my $self = shift; | ||
die sprintf('ERROR: Login failed %s', $self->name) | ||
if !$self->login(); | ||
return $self; | ||
} | ||
|
||
sub add_user($name, $password, $storage='rfc2307', $algorithm=undef) { } | ||
|
||
sub remove_user { } | ||
|
||
sub search_user { } | ||
|
||
sub _check_user_profile($self) { | ||
my $user_sql = Ravada::Auth::SQL->new(name => $self->name); | ||
if ( $user_sql->id ) { | ||
if ($user_sql->external_auth ne 'openid') { | ||
$user_sql->external_auth('openid'); | ||
} | ||
return; | ||
} | ||
|
||
Ravada::Auth::SQL::add_user(name => $self->name, is_external => 1, is_temporary => 0 | ||
, external_auth => 'openid'); | ||
} | ||
|
||
sub is_admin { } | ||
|
||
sub is_external { } | ||
|
||
sub login_external($name, $header) { | ||
|
||
for my $field (qw(OIDC_CLAIM_exp OIDC_access_token_expires)) { | ||
if ( $header->{$field} < time() ) { | ||
warn localtime($header->{$field})." $field expired \n"; | ||
return 0; | ||
} | ||
} | ||
|
||
my $self = Ravada::Auth::OpenID->new(name => $name); | ||
$self->_check_user_profile(); | ||
return $self; | ||
} | ||
|
||
sub login($self) { | ||
my $user_sql = Ravada::Auth::SQL->new(name => $self->name); | ||
return 1 if $user_sql->external_auth && $user_sql->external_auth eq 'openid'; | ||
return 1; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters