File: Mock_OAuthDataStore.php

package info (click to toggle)
liboauth-php 0~svn1262-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 224 kB
  • ctags: 522
  • sloc: php: 1,591; xml: 12; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,506 bytes parent folder | download
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
51
52
53
54
55
56
57
<?php

/**
 * A mock store for testing
 */
class Mock_OAuthDataStore extends OAuthDataStore {
	private $consumer;
	private $request_token;
	private $access_token;
	private $nonce;

	function __construct() {
		$this->consumer = new OAuthConsumer("key", "secret", NULL);
		$this->request_token = new OAuthToken("requestkey", "requestsecret", 1);
		$this->access_token = new OAuthToken("accesskey", "accesssecret", 1);
		$this->nonce = "nonce";
	}

	function lookup_consumer($consumer_key) {
		if ($consumer_key == $this->consumer->key) return $this->consumer;
		return NULL;
	}

	function lookup_token($consumer, $token_type, $token) {
		$token_attrib = $token_type . "_token";
		if ($consumer->key == $this->consumer->key
			&& $token == $this->$token_attrib->key) {
			return $this->$token_attrib;
		}
		return NULL;
	}

	function lookup_nonce($consumer, $token, $nonce, $timestamp) {
		if ($consumer->key == $this->consumer->key
			&& (($token && $token->key == $this->request_token->key)
				|| ($token && $token->key == $this->access_token->key))
			&& $nonce == $this->nonce) {
			return $this->nonce;
		}
		return NULL;
	}

	function new_request_token($consumer, $callback = null) {
		if ($consumer->key == $this->consumer->key) {
			return $this->request_token;
		}
		return NULL;
	}

	function new_access_token($token, $consumer, $verifier = null) {
		if ($consumer->key == $this->consumer->key
			&& $token->key == $this->request_token->key) {
			return $this->access_token;
		}
		return NULL;
	}
}