Amon2-Auth-Site-LINE

 view release on metacpan or  search on metacpan

lib/Amon2/Auth/Site/LINE.pm  view on Meta::CPAN

            $current_uri->as_string;
        };
        my $res = $self->ua->post($self->access_token_url => +{
            grant_type    => 'authorization_code',
            code          => $c->req->param('code'),
            redirect_uri  => $redirect_uri,
            client_id     => $self->client_id,
            client_secret => $self->client_secret,
        });
        unless ($res->is_success) {
            warn $res->decoded_content;
            return $callback->{on_error}->($res->status_line);
        }

        $token_data = decode_json($res->content);
        %api_response = (%api_response, %$token_data);
    }

    # verify access token
    my $verify_data;
    {
        my $uri = URI->new($self->verify_url);
        $uri->query_form(access_token => $token_data->{access_token});

        my $res = $self->ua->get($uri->as_string);
        unless ($res->is_success) {
            warn $res->decoded_content;
            return $callback->{on_error}->($res->status_line);
        }

        $verify_data = decode_json($res->content);
        if ($verify_data->{client_id} ne $self->client_id) {
            return $callback->{on_error}->('client_id mismatch');
        }

        push @args, $token_data->{access_token};
        %api_response = (%api_response, %$verify_data);
    }

    # get user profile
    if ($self->user_info && $verify_data->{scope} =~ /\bprofile\b/) {
        my $uri = URI->new($self->profile_url);
        my $res = $self->ua->get(
            $uri->as_string,
            Authorization => 'Bearer ' . $token_data->{access_token},
        );
        $res->is_success or do {
            warn $res->decoded_content;
            return $callback->{on_error}->($res->decoded_content);
        };
        my $user = decode_json($res->content);
        %api_response = (%api_response, %$user);
    }
    push @args, \%api_response;

    $self->clear_state($c);
    $self->clear_nonce($c);

    $callback->{on_finished}->(@args);



( run in 0.401 second using v1.01-cache-2.11-cpan-26ccb49234f )