| 1 | package Imgur::API::Endpoint::OAuth; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Mouse; | ||
| 5 | use feature qw(say); | ||
| 6 | extends 'Imgur::API::Endpoint'; | ||
| 7 | |||
| 8 | sub auth_url { | ||
| 9 | my ($this,%options) = @_; | ||
| 10 | |||
| 11 | $options{state}||=''; | ||
| 12 | |||
| 13 | return $this->path("oauth2/authorize",[],[],{})."?response_type=$options{grant_type}&client_id=".$this->dispatcher->client_id."&state=$options{state}"; | ||
| 14 | } | ||
| 15 | |||
| 16 | |||
| 17 | sub token { | ||
| 18 | my ($this,%p) = @_; | ||
| 19 | |||
| 20 | $p{client_id} = $this->dispatcher->client_id; | ||
| 21 | $p{client_secret} = $this->dispatcher->client_secret; | ||
| 22 | |||
| 23 | |||
| 24 | my $url = $this->path("oauth2/token",[],[],\%p); | ||
| 25 | |||
| 26 | say $url; | ||
| 27 | |||
| 28 | return $this->dispatcher->request($url,'post',\%p); | ||
| 29 | |||
| 30 | } | ||
| 31 | |||
| 32 | 1; | ||
| 33 | __PACKAGE__->meta->make_immutable; | ||
| 34 |