Catalyst Maintainable web apps made easy! #127

Use the key in REST controller

sub begin : ActionClass('Deserialize') {
    my ($self, $c) = @_;

    my $key  = $c->req->header('X-DoqueueKey');
    my $key_obj = $c->model('DBIC::ApiKeys')->find($key);
    my $user = eval { $key_obj->owner };

    # require either logged in user or API key
    if ( !$c->user && !$user ) {
        # login failed
        $c->res->status(403); # forbidden
        $c->res->body("You are not authorized to use the REST API.");
        $c->detach;
    }

    $c->user($user) if $user;
}
Copyright © 2007 Jonathan Rockway