X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FModels%2FTwitchToken.php;fp=app%2FModels%2FTwitchToken.php;h=9b15977b41e881afae2cf5c367c09ed553156cee;hb=898d01d4ac5ccaa23621abda0761a893ff8c1074;hp=0000000000000000000000000000000000000000;hpb=c4835dcd53401c4e618ba077726d655d476a82c8;p=alttp.git diff --git a/app/Models/TwitchToken.php b/app/Models/TwitchToken.php new file mode 100644 index 0000000..9b15977 --- /dev/null +++ b/app/Models/TwitchToken.php @@ -0,0 +1,47 @@ +scope)); + } + + public function refresh() { + $rsp = Http::post('https://id.twitch.tv/oauth2/token', [ + 'client_id' => config('twitch.client_id'), + 'client_secret' => config('twitch.client_secret'), + 'grant_type' => 'refresh_token', + 'refresh_token' => $this->refresh, + ]); + if (!$rsp->successful()) { + throw new \Exception($rsp['message']); + } + $this->type = $rsp['token_type']; + $this->scope = $rsp['scope']; + $this->access = $rsp['access_token']; + $this->refresh = $rsp['refresh_token']; + $this->save(); + } + + protected $casts = [ + 'scope' => 'array', + ]; + + protected $hidden = [ + 'access', + 'refresh', + ]; + +}