Go to the documentation of this file.00001 <?php
00002
00003
00004 define("MONGO_CONNECTION", "mongodb://user:pass@mongoserver/mydb");
00005 define("MONGO_DB", "mydb");
00006
00007 include "../../../lib/oauth.php";
00008
00009
00010
00011
00012 class MongoOAuth2 extends OAuth2 {
00013
00014 private $db;
00015
00016
00017
00018
00019 public function __construct() {
00020 parent::__construct();
00021
00022 $mongo = new Mongo(MONGO_CONNECTION);
00023 $this->db = $mongo->selectDB(MONGO_DB);
00024 }
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 public function addClient($client_id, $client_secret, $redirect_uri) {
00040 $this->db->clients->insert(array(
00041 "_id" => $client_id,
00042 "pw" => $client_secret,
00043 "redirect_uri" => $redirect_uri
00044 ));
00045 }
00046
00047
00048
00049
00050
00051
00052
00053 protected function checkClientCredentials($client_id, $client_secret = NULL) {
00054 $client = $this->db->clients->findOne(array("_id" => $client_id, "pw" => $client_secret));
00055 return $client !== NULL;
00056 }
00057
00058
00059
00060
00061 protected function getRedirectUri($client_id) {
00062 $uri = $this->db->clients->findOne(array("_id" => $client_id), array("redirect_uri"));
00063 return $uri !== NULL ? $uri["redirect_uri"] : FALSE;
00064 }
00065
00066
00067
00068
00069 protected function getAccessToken($oauth_token) {
00070 return $this->db->tokens->findOne(array("_id" => $oauth_token));
00071 }
00072
00073
00074
00075
00076 protected function setAccessToken($oauth_token, $client_id, $expires, $scope = NULL) {
00077 $this->db->tokens->insert(array(
00078 "_id" => $oauth_token,
00079 "client_id" => $client_id,
00080 "expires" => $expires,
00081 "scope" => $scope
00082 ));
00083 }
00084
00085
00086
00087
00088 protected function getSupportedGrantTypes() {
00089 return array(
00090 OAUTH2_GRANT_TYPE_AUTH_CODE,
00091 );
00092 }
00093
00094
00095
00096
00097 protected function getAuthCode($code) {
00098 $stored_code = $this->db->auth_codes->findOne(array("_id" => $code));
00099 return $stored_code !== NULL ? $stored_code : FALSE;
00100 }
00101
00102
00103
00104
00105 protected function setAuthCode($code, $client_id, $redirect_uri, $expires, $scope = NULL) {
00106 $this->db->auth_codes->insert(array(
00107 "_id" => $code,
00108 "client_id" => $client_id,
00109 "redirect_uri" => $redirect_uri,
00110 "expires" => $expires,
00111 "scope" => $scope
00112 ));
00113 }
00114 }