diff options
author | Michiel de Jong <michiel@unhosted.org> | 2012-02-22 18:05:52 +0000 |
---|---|---|
committer | Michiel de Jong <michiel@unhosted.org> | 2012-02-22 18:05:52 +0000 |
commit | 9850820b4276b197433bb64d84ed085cdcd01e0e (patch) | |
tree | 54a01be8be5038122820ca77dbe6eb85aaacd906 /apps/remoteStorage/BearerAuth.php | |
parent | 6c6b570ff15cfa9da6b1ab8b7e56ef0a82c96086 (diff) | |
download | nextcloud-server-9850820b4276b197433bb64d84ed085cdcd01e0e.tar.gz nextcloud-server-9850820b4276b197433bb64d84ed085cdcd01e0e.zip |
BearerAuth and multiple tokens support in remoteStorage app
Diffstat (limited to 'apps/remoteStorage/BearerAuth.php')
-rw-r--r-- | apps/remoteStorage/BearerAuth.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/apps/remoteStorage/BearerAuth.php b/apps/remoteStorage/BearerAuth.php new file mode 100644 index 00000000000..ebcf189dfb9 --- /dev/null +++ b/apps/remoteStorage/BearerAuth.php @@ -0,0 +1,61 @@ +<?php + +/** + * HTTP Bearer Authentication handler + * + * Use this class for easy http authentication setup + * + * @package Sabre + * @subpackage HTTP + * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ +class Sabre_HTTP_BearerAuth extends Sabre_HTTP_AbstractAuth { + + /** + * Returns the supplied username and password. + * + * The returned array has two values: + * * 0 - username + * * 1 - password + * + * If nothing was supplied, 'false' will be returned + * + * @return mixed + */ + public function getUserPass() { + + // Apache and mod_php + if (($user = $this->httpRequest->getRawServerValue('PHP_AUTH_USER')) && ($pass = $this->httpRequest->getRawServerValue('PHP_AUTH_PW'))) { + + return array($user,$pass); + + } + + // Most other webservers + $auth = $this->httpRequest->getHeader('Authorization'); + + if (!$auth) return false; + + if (strpos(strtolower($auth),'bearer')!==0) return false; + + return explode(':', base64_decode(substr($auth, 7))); + + } + + /** + * Returns an HTTP 401 header, forcing login + * + * This should be called when username and password are incorrect, or not supplied at all + * + * @return void + */ + public function requireLogin() { + + $this->httpResponse->setHeader('WWW-Authenticate','Basic realm="' . $this->realm . '"'); + $this->httpResponse->sendStatus(401); + + } + +} |