OpenID-Lite-Extension-UI

 view release on metacpan or  search on metacpan

lib/OpenID/Lite/Extension/UI.pm  view on Meta::CPAN

package OpenID::Lite::Extension::UI;

use strict;
use warnings;
use base 'Exporter';

our $VERSION = '0.01';
our @EXPORT_OK = qw(UI_NS UI_POPUP_NS UI_LANG_NS UI_NS_ALIAS);

use constant UI_NS       => q{http://specs.openid.net/extensions/ui/1.0};
use constant UI_POPUP_NS => q{http://specs.openid.net/extensions/ui/1.0/popup};
use constant UI_LANG_NS  => q{http://specs.openid.net/extensions/ui/1.0/lang-pref};
use constant UI_NS_ALIAS => q{ui};

1;

=head1 NAME

OpenID::Lite::Extension::UI - UI extension plugin for OpenID::Lite

=head1 SYNOPSIS

RP side

    sub login {
        ...
        my $checkid_req = $rp->begin( $identifier )
            or $your_app->error( $rp->errstr );

        $ui_req = OpenID::Lite::Extension::UI->new;
        $ui_req->mode('popup');
        $ui_req->lang('en-US');
        $checkid_req->add_extension( $ui_req );

        $your_app->redirect_to( $checkid_req->redirect_url( ... ) );
    }

OP side

    my $res = $op->handle_request( $your_app->request );

    if ( $res->is_for_setup ) {

        my %option;
        my $ui_req = OpenID::Lite::Extension::UI::Request->from_provider_response($res);
        if ($ui_req) {
            if ($ui_req->mode eq 'popup') {
                $option{template} = 'openid_popup.tt';
            }
        }
        $your_app->render( %option );
    }...

=head1 DESCRIPTION

This module is plugin for OpenID::Lite to acomplish UI extension flow on easy way.
http://wiki.openid.net/f/openid_ui_extension_draft01.html

lib/OpenID/Lite/Extension/UI/Request.pm  view on Meta::CPAN


has 'lang' => (
    is      => 'rw',
    isa     => 'Str',
#    default => q{en-US}
);

has 'mode' => (
    is      => 'rw',
    isa     => 'Str',
#    default => q{popup},
);

# RP should create popup to be 450 pixels wide and 500 pixels tall.
# The popup must have the address bar displayed.
# The popup must be in a standalone browser window.
# The contents of the popup must not be framed by the RP.
override 'append_to_params' => sub {
    my ( $self, $params ) = @_;
    $params->register_extension_namespace( UI_NS_ALIAS, UI_NS );
    $params->set_extension( UI_NS_ALIAS, 'lang', $self->lang );
    $params->set_extension( UI_NS_ALIAS, 'mode', $self->mode );
};

sub from_provider_response {
    my ( $class, $res ) = @_;
    my $message = $res->req_params->copy();

t/01_request.t  view on Meta::CPAN

    secret     => pack("H*","9c1537e999f93fa31f17346c2f620aaf0518bc0d"),
    type       => "HMAC-SHA1",
);

my $checkid = OpenID::Lite::RelyingParty::CheckID::Request->new(
    association => $assoc,
    service     => $service,
);

my $ui = OpenID::Lite::Extension::UI::Request->new;
$ui->mode('popup');
$ui->lang('en-US');

$checkid->add_extension( $ui );

my $url = $checkid->redirect_url(
    return_to => q{http://example.com/return_to},
    realm     => q{http://example.com/},
);

like($url, qr/openid\.ui\.mode\=popup/);
unlike($url, qr/openid\.ui\.mode\=hoge/);
like($url, qr/openid\.ui\.lang\=en\-US/);
unlike($url, qr/openid\.ui\.lang\=ja\-JP/);


my $params = $checkid->_params->copy();

my $op_res = OpenID::Lite::Provider::Response->new(
    type          => 'setup',
    req_params    => $params,
    res_params    => $params,
    setup_url     => q{http://localhost/openid/setup},
    endpoint_url  => q{http://localhost/openid/endpoint},
);

my $req = OpenID::Lite::Extension::UI::Request->from_provider_response($op_res);
ok($req);
is($req->mode, 'popup');
is($req->lang, 'en-US');




( run in 0.775 second using v1.01-cache-2.11-cpan-364913b4093 )