Login Plugins
Login Plugins mostly play a support role: They can be called by all other plugins: Metadata, Downloader and Script Plugins. Their role is to provide a configured Mojo::UserAgent object that can be used to perform authenticated operations on a remote Web service.

Required subroutines

Only one subroutine needs to be implemented for the module to be recognized: do_login, which contains your working code. You're free to implement other subroutines for cleaner code, of course.

Expected Input

When executing your Plugin, LRR will call the do_login subroutine and give it the following variables:
1
sub do_login {
2
3
#First lines you should have in the subroutine
4
shift;
5
my ($param1, $param2, $param3) = @_; # Plugin parameters
Copied!
The variables match the parameters you've entered in the plugin_info subroutine.

Expected Output

Your plugin must return a Mojo::UserAgent object. That's it!
There's no particular error handling for Login Plugins at the moment, so I recommend you return an empty UserAgent if Login fails and handle the error in the matching Metadata/Script plugin.

Plugin Template

1
package LANraragi::Plugin::Login::MyNewPlugin;
2
3
use strict;
4
use warnings;
5
6
use Mojo::UserAgent;
7
use LANraragi::Utils::Logging qw(get_logger);
8
9
#Meta-information about your plugin.
10
sub plugin_info {
11
12
return (
13
#Standard metadata
14
name => "Login Plugin",
15
type => "login",
16
namespace => "dummylogin",
17
author => "Hackerman",
18
version => "0.001",
19
description => "This is base boilerplate for writing LRR plugins.",
20
#If your plugin uses/needs custom arguments, input their name here.
21
#This name will be displayed in plugin configuration next to an input box.
22
parameters => [
23
{type => "bool", desc => "Enable logging in to service X", default_value => "1"},
24
{type => "int", desc => "User ID"},
25
{type => "string", desc => "Password"}
26
]
27
);
28
29
}
30
31
# Mandatory function to be implemented by your login plugin
32
# Returns a Mojo::UserAgent object only!
33
sub do_login {
34
35
# Login plugins only receive the parameters entered by the user.
36
shift;
37
my ( $loginenabled, $uID, $password) = @_;
38
39
my $logger = get_logger( "Undernet Login", "plugins" );
40
my $ua = Mojo::UserAgent->new;
41
42
if ($loginenabled) {
43
44
$ua->cookie_jar->add(
45
Mojo::Cookie::Response->new(
46
name => 'userID',
47
value => $uID,
48
domain => 'example.com',
49
path => '/'
50
)
51
);
52
53
$ua->cookie_jar->add(
54
Mojo::Cookie::Response->new(
55
name => 'password',
56
value => $password,
57
domain => 'example.com',
58
path => '/'
59
)
60
);
61
62
} else {
63
$logger->info( "No cookies provided, returning blank UserAgent.");
64
}
65
66
return $ua;
67
}
68
69
1;
Copied!
Last modified 10d ago