I converted my downloaded pkcs12 key with -nodes option (password remove).
openssl pkcs12 -in privatekey.p12 -nodes -out test.pem
And try again.
But "invalid_grant" error occured.
Please help me..
----------------------------------source code -----------------------------------
get '/auth/:dest' => sub{
my $self = shift;
my $dest = $self->param('dest');
my $header = qq<{"alg":"RS256","typ":"JWT"}>;
my $iat = time();
my $exp = $iat + 3600;
my $claim = '{
"exp":$exp,
"iat":$iat
}';
my $assertion = join(".", urlsafe_b64encode($header), urlsafe_b64encode($claim));
my $key_text = read_file( "/home/private/test.pem" );
print "assertion=$assertion";
my $rsa_key = Crypt::OpenSSL::RSA->new_private_key($key_text) || die "$!";
$rsa_key->use_pkcs1_padding();
my $signature = $rsa_key->sign(sha256_base64($assertion));
my $signed_signature = urlsafe_b64encode($signature);
my $signed_assertion = join(".", $assertion, $signed_signature);
print $signed_assertion;
my $ua = LWP::UserAgent->new;
my %args =(
Content_Type => 'application/x-www-form-urlencoded',
Content => {
'grant_type' => 'assertion',
'assertion' => $signed_assertion,
}
);
my $result = JSON->new->utf8(0)->decode($r->content);
print $r->content;
2012年7月11日水曜日 0時58分36秒 UTC+9 hatobus: