forked from tomaj/nette-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticBearerTokenRepository.php
More file actions
50 lines (45 loc) · 1.15 KB
/
Copy pathStaticBearerTokenRepository.php
File metadata and controls
50 lines (45 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Tomaj\NetteApi\Misc;
class StaticBearerTokenRepository implements BearerTokenRepositoryInterface
{
/**
* array
*/
private $validTokens = [];
/**
* Create static bearer token repository.
* You can pass multiple tokens that will be available for your api.
* Format is associtive array where key is token string and value is IP range
*
* Example:
* ['ef0p9iwehjgoihrgrsdgfoihw4t' => '*']
*
* Or:
* ['asfoihegoihregoihrhgrehg' => '127.0.0.1', 'asfo9uyewtoiyewgt4ty4r' => '*']
*
* @see BearerTokenAuthorization#isValidIp for all available Ip range formats
*
* @param array $validTokens
*/
public function __construct($validTokens = [])
{
$this->validTokens = $validTokens;
}
/**
* {@inheritdoc}
*/
public function validToken($token)
{
return in_array($token, array_keys($this->validTokens));
}
/**
* {@inheritdoc}
*/
public function ipRestrictions($token)
{
if (isset($this->validTokens[$token])) {
return $this->validTokens[$token];
}
return false;
}
}