<?php
 namespace League\OAuth2\Client\Tool; use League\OAuth2\Client\Token\AccessToken; use League\OAuth2\Client\Token\AccessTokenInterface; trait MacAuthorizationTrait { abstract protected function getTokenId(AccessToken $token); abstract protected function getMacSignature($id, $ts, $nonce); abstract protected function getRandomState($length = 32); protected function getAuthorizationHeaders($token = null) { if ($token === null) { return []; } $ts = time(); $id = $this->getTokenId($token); $nonce = $this->getRandomState(16); $mac = $this->getMacSignature($id, $ts, $nonce); $parts = []; foreach (compact('id', 'ts', 'nonce', 'mac') as $key => $value) { $parts[] = sprintf('%s="%s"', $key, $value); } return ['Authorization' => 'MAC ' . implode(', ', $parts)]; } } 