OAuthCommonStorageSymfonySession

The Gravity Forms Salesforce Add-On OAuth Common Storage SymfonySession class.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/Common/Storage/SymfonySession.php  
  1. class SymfonySession implements TokenStorageInterface 
  2. private $session; 
  3. private $sessionVariableName; 
  4. private $stateVariableName; 
  5.  
  6. /** 
  7. * @param SessionInterface $session 
  8. * @param bool $startSession 
  9. * @param string $sessionVariableName 
  10. * @param string $stateVariableName 
  11. */ 
  12. public function __construct( 
  13. SessionInterface $session,  
  14. $startSession = true,  
  15. $sessionVariableName = 'lusitanian_oauth_token',  
  16. $stateVariableName = 'lusitanian_oauth_state' 
  17. ) { 
  18. $this->session = $session; 
  19. $this->sessionVariableName = $sessionVariableName; 
  20. $this->stateVariableName = $stateVariableName; 
  21.  
  22. /** 
  23. * {@inheritDoc} 
  24. */ 
  25. public function retrieveAccessToken($service) 
  26. if ($this->hasAccessToken($service)) { 
  27. // get from session 
  28. $tokens = $this->session->get($this->sessionVariableName); 
  29.  
  30. // one item 
  31. return $tokens[$service]; 
  32.  
  33. throw new TokenNotFoundException('Token not found in session, are you sure you stored it?'); 
  34.  
  35. /** 
  36. * {@inheritDoc} 
  37. */ 
  38. public function storeAccessToken($service, TokenInterface $token) 
  39. // get previously saved tokens 
  40. $tokens = $this->session->get($this->sessionVariableName); 
  41.  
  42. if (!is_array($tokens)) { 
  43. $tokens = array(); 
  44.  
  45. $tokens[$service] = $token; 
  46.  
  47. // save 
  48. $this->session->set($this->sessionVariableName, $tokens); 
  49.  
  50. // allow chaining 
  51. return $this; 
  52.  
  53. /** 
  54. * {@inheritDoc} 
  55. */ 
  56. public function hasAccessToken($service) 
  57. // get from session 
  58. $tokens = $this->session->get($this->sessionVariableName); 
  59.  
  60. return is_array($tokens) 
  61. && isset($tokens[$service]) 
  62. && $tokens[$service] instanceof TokenInterface; 
  63.  
  64. /** 
  65. * {@inheritDoc} 
  66. */ 
  67. public function clearToken($service) 
  68. // get previously saved tokens 
  69. $tokens = $this->session->get($this->sessionVariableName); 
  70.  
  71. if (is_array($tokens) && array_key_exists($service, $tokens)) { 
  72. unset($tokens[$service]); 
  73.  
  74. // Replace the stored tokens array 
  75. $this->session->set($this->sessionVariableName, $tokens); 
  76.  
  77. // allow chaining 
  78. return $this; 
  79.  
  80. /** 
  81. * {@inheritDoc} 
  82. */ 
  83. public function clearAllTokens() 
  84. $this->session->remove($this->sessionVariableName); 
  85.  
  86. // allow chaining 
  87. return $this; 
  88.  
  89. /** 
  90. * {@inheritDoc} 
  91. */ 
  92. public function retrieveAuthorizationState($service) 
  93. if ($this->hasAuthorizationState($service)) { 
  94. // get from session 
  95. $states = $this->session->get($this->stateVariableName); 
  96.  
  97. // one item 
  98. return $states[$service]; 
  99.  
  100. throw new AuthorizationStateNotFoundException('State not found in session, are you sure you stored it?'); 
  101.  
  102. /** 
  103. * {@inheritDoc} 
  104. */ 
  105. public function storeAuthorizationState($service, $state) 
  106. // get previously saved tokens 
  107. $states = $this->session->get($this->stateVariableName); 
  108.  
  109. if (!is_array($states)) { 
  110. $states = array(); 
  111.  
  112. $states[$service] = $state; 
  113.  
  114. // save 
  115. $this->session->set($this->stateVariableName, $states); 
  116.  
  117. // allow chaining 
  118. return $this; 
  119.  
  120. /** 
  121. * {@inheritDoc} 
  122. */ 
  123. public function hasAuthorizationState($service) 
  124. // get from session 
  125. $states = $this->session->get($this->stateVariableName); 
  126.  
  127. return is_array($states) 
  128. && isset($states[$service]) 
  129. && null !== $states[$service]; 
  130.  
  131. /** 
  132. * {@inheritDoc} 
  133. */ 
  134. public function clearAuthorizationState($service) 
  135. // get previously saved tokens 
  136. $states = $this->session->get($this->stateVariableName); 
  137.  
  138. if (is_array($states) && array_key_exists($service, $states)) { 
  139. unset($states[$service]); 
  140.  
  141. // Replace the stored tokens array 
  142. $this->session->set($this->stateVariableName, $states); 
  143.  
  144. // allow chaining 
  145. return $this; 
  146.  
  147. /** 
  148. * {@inheritDoc} 
  149. */ 
  150. public function clearAllAuthorizationStates() 
  151. $this->session->remove($this->stateVariableName); 
  152.  
  153. // allow chaining 
  154. return $this; 
  155.  
  156. /** 
  157. * @return Session 
  158. */ 
  159. public function getSession() 
  160. return $this->session;