Requires the following configuration options enable_github_login = 1 github_client_id github_client_secret Or github_client_secret_file which points to a file with the secret
GNQYRBAGAODY5KQX4E5AZMBGA4KFMNKFALL2Y3CVRJ6NS3EFE3TAC
HPGWVEFKM3DYLNLPMWLZI5VZXURUSVJ4FM2DPJCPR5HBOEQPASQQC
BVFH3BWMD7RNL7WMB3LKEVQ3HJN44ZXM5RGLYCMYRDQKNR24X46AC
2DHE2ZAKR4AU7OE6E5CYNFWVGQXLHEX5LFKVU43PMBVX3QW6RHFAC
J5UVLXOK6EDIL5I7VKWH4V2QDS4DPD7FHRK6XBWSXFRQS4JKXFZQC
LZVO64YG43JD7YMZSCTZNOBS5ROZA4FMPKJW2YOMHX2V5PTGBVWQC
LSZLZHJYGXZTCNH4JUXU7W23MW5PBVM4OBMWRRVNEDROMIBUVQNAC
XJRJ4J7M6BC433TBLWHHKX7UYYCFX6M7ZQLUEYYTREPCSM6M3RDQC
3QWDDLBR5DGFK5Y3TDMK55R2SCHRHFVO2KW2BMZGIYRTIQEZC45AC
JATZRMWWP6ENJRULJ2PFW6NT35C4N3WVWACAFFNI5DKF2H6AY7FAC
JFW656FT5JSDCA5NBNFGTJABIR2LR5VRDRYI7KF54PYNFDSL4DMAC
QL55ECJ6KMMBUOWQ6LKSOVN7L43CH4S6SPE2AQ3VX3KSGC32RP4AC
XHOZT4WTBN3Y7Q2MBANFS65X4HYL6SGPA7JNB7T7OD726SU2ACWAC
BPT4WJ7UWVRNXFO2GD2I2P5Z5PHKZDRVIOAAUW23JI5H4GCHLGSAC
D44B24QC6NCED6DVUYP2IJJEVBG2JNBKPBRRSLI5UXQTKA23DJQQC
N22GPKYTOLZLBGTGDATQDVZ4R5APZEAOIA7L32X4UXBH4XNI7MWAC
BKMQXGBOQIANQGBI3JMMVE3CA32SJF2MI4XMXAJA3EWZ2MYPZDTQC
}
sub github_login :Path('/github-login') Args(0) {
my ($self, $c) = @_;
error($c, "Logging in via GitHub is not enabled.") unless $c->config->{enable_github_login};
my $client_id = $c->config->{github_client_id} or die "github_client_id not configured.";
my $client_secret = $c->config->{github_client_secret} // do {
my $client_secret_file = $c->config->{github_client_secret_file} or die "github_client_secret nor github_client_secret_file is configured.";
my $client_secret = read_file($client_secret_file);
$client_secret =~ s/\s+//;
$client_secret;
};
die "No github secret configured" unless $client_secret;
my $ua = new LWP::UserAgent;
my $response = $ua->post(
'https://github.com/login/oauth/access_token',
{
client_id => $client_id,
client_secret => $client_secret,
code => ($c->req->params->{code} // die "No token."),
}, Accept => 'application/json');
error($c, "Did not get a response from GitHub.") unless $response->is_success;
my $data = decode_json($response->decoded_content) or die;
my $access_token = $data->{access_token} // die "No access_token in response from GitHub.";
$response = $ua->get('https://api.github.com/user', Authorization => "token $access_token");
error($c, "Did not get a response from GitHub for user info.") unless $response->is_success;
$data = decode_json($response->decoded_content) or die;
doEmailLogin($self, $c, "github", $data->{email}, $data->{name} // undef);
$c->res->redirect($c->uri_for($c->res->cookies->{'after_github'}));
}
sub github_redirect :Path('/github-redirect') Args(0) {
my ($self, $c) = @_;
error($c, "Logging in via GitHub is not enabled.") unless $c->config->{enable_github_login};
my $client_id = $c->config->{github_client_id} or die "github_client_id not configured.";
my $after = "/" . $c->req->params->{after};
$c->res->cookies->{'after_github'} = {
name => 'after_github',
value => $after,
};
$c->res->redirect("https://github.com/login/oauth/authorize?client_id=$client_id");
die "$0: type must be `hydra' or `google'\n"
if defined $type && $type ne "hydra" && $type ne "google";
die "$0: type must be `hydra', `google' or `github'\n"
if defined $type && $type ne "hydra" && $type ne "google" && $type ne "github";