~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Helper/McaasGrant.php

  • Committer: Dan Garner
  • Date: 2015-09-29 15:16:59 UTC
  • mto: (454.2.11) (471.2.2)
  • mto: This revision was merged to the branch mainline in revision 468.
  • Revision ID: git-v1:ae24387a7b1397750b6ec86d0f286373da05eb16
Fixed Display Version Information Form (not showing media name)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Spring Signage Ltd - http://www.springsignage.com
4
 
 * Copyright (C) 2016 Spring Signage Ltd
5
 
 * (McaasGrant.php)
6
 
 */
7
 
 
8
 
 
9
 
namespace Xibo\Helper;
10
 
 
11
 
 
12
 
use League\OAuth2\Server\Entity\AccessTokenEntity;
13
 
use League\OAuth2\Server\Entity\ClientEntity;
14
 
use League\OAuth2\Server\Entity\SessionEntity;
15
 
use League\OAuth2\Server\Exception\InvalidClientException;
16
 
use League\OAuth2\Server\Grant\AbstractGrant;
17
 
use League\OAuth2\Server\Util\SecureKey;
18
 
 
19
 
/**
20
 
 * Class McaasGrant
21
 
 * @package Xibo\Helper
22
 
 */
23
 
class McaasGrant extends AbstractGrant
24
 
{
25
 
    /**
26
 
     * Grant identifier
27
 
     *
28
 
     * @var string
29
 
     */
30
 
    protected $identifier = 'mcaas';
31
 
 
32
 
    /**
33
 
     * Response type
34
 
     *
35
 
     * @var string
36
 
     */
37
 
    protected $responseType = null;
38
 
 
39
 
    /**
40
 
     * AuthServer instance
41
 
     *
42
 
     * @var \League\OAuth2\Server\AuthorizationServer
43
 
     */
44
 
    protected $server = null;
45
 
 
46
 
    /**
47
 
     * Access token expires in override
48
 
     *
49
 
     * @var int
50
 
     */
51
 
    protected $accessTokenTTL = null;
52
 
 
53
 
    /**
54
 
     * @var ClientEntity
55
 
     */
56
 
    protected $client;
57
 
 
58
 
    /**
59
 
     * Set Client
60
 
     * @param string $clientId
61
 
     * @param string $clientSecret
62
 
     * @return self
63
 
     * @throws InvalidClientException
64
 
     */
65
 
    public function setClient($clientId, $clientSecret)
66
 
    {
67
 
        $this->client = $this->server->getClientStorage()->get(
68
 
            $clientId,
69
 
            $clientSecret,
70
 
            null,
71
 
            $this->getIdentifier()
72
 
        );
73
 
 
74
 
        if (($this->client instanceof ClientEntity) === false) {
75
 
            throw new InvalidClientException();
76
 
        }
77
 
 
78
 
        return $this;
79
 
    }
80
 
 
81
 
    /**
82
 
     * Complete the client credentials grant
83
 
     *
84
 
     * @return string
85
 
     *
86
 
     * @throws
87
 
     */
88
 
    public function completeFlow()
89
 
    {
90
 
        // Validate any scopes that are in the request (should always return default)
91
 
        $scopes = $this->validateScopes('', $this->client);
92
 
 
93
 
        // Create a new session
94
 
        $session = new SessionEntity($this->server);
95
 
        $session->setOwner('client', $this->client->getId());
96
 
        $session->associateClient($this->client);
97
 
 
98
 
        // Generate an access token
99
 
        $accessToken = new AccessTokenEntity($this->server);
100
 
        $accessToken->setId(SecureKey::generate());
101
 
        $accessToken->setExpireTime($this->getAccessTokenTTL() + time());
102
 
 
103
 
        // Associate scopes with the session and access token
104
 
        foreach ($scopes as $scope) {
105
 
            $session->associateScope($scope);
106
 
        }
107
 
 
108
 
        foreach ($session->getScopes() as $scope) {
109
 
            $accessToken->associateScope($scope);
110
 
        }
111
 
 
112
 
        // Save everything
113
 
        $session->save();
114
 
        $accessToken->setSession($session);
115
 
        $accessToken->save();
116
 
 
117
 
        return $accessToken->getId();
118
 
    }
119
 
}
 
 
b'\\ No newline at end of file'