-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F/http #166
Open
sebastiansterk
wants to merge
9
commits into
master
Choose a base branch
from
f/http
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
F/http #166
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
214ec5c
Add files via upload
sebastiansterk e688344
Update README.md
sebastiansterk 16e4fc5
Update README.md
sebastiansterk 23accc3
Update README.md
sebastiansterk 22a641e
Update http.php
sebastiansterk a941132
Update info.xml
sebastiansterk 3310be7
Update appinfo, fix indentation
sebastiansterk 42be138
Merge branch 'master' into f/http
sebastiansterk c593566
change public function to private class
sebastiansterk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2021 Sebastian Sterk <sebastian@wiuwiu.de> | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
/** | ||
* User authentication against a generic HTTP auth interface | ||
* | ||
* @category Apps | ||
* @package UserExternal | ||
* @author Sebastian Sterk https://wiuwiu.de/Imprint | ||
* @license http://www.gnu.org/licenses/agpl AGPL | ||
*/ | ||
class OC_User_HTTP extends \OCA\user_external\Base { | ||
private $hashAlgo; | ||
private $accessKey; | ||
private $authenticationEndpoint; | ||
|
||
public function __construct($authenticationEndpoint, $hashAlgo = false, $accessKey = '') { | ||
parent::__construct($authenticationEndpoint); | ||
$this->authenticationEndpoint = $authenticationEndpoint; | ||
$this->hashAlgo = $hashAlgo; | ||
$this->accessKey = $accessKey; | ||
} | ||
|
||
public function sendUserData($user, $password){ | ||
if($this->hashAlgo !== false){ | ||
$password = $this->hashPassword($password); | ||
} | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, $this->authenticationEndpoint); | ||
curl_setopt($ch, CURLOPT_HEADER, true); | ||
curl_setopt($ch, CURLOPT_NOBODY, true); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_POST, 1); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, | ||
http_build_query(array( | ||
'accessKey' => $this->accessKey, | ||
'user' => $user, | ||
'password' => $password | ||
) | ||
) | ||
); | ||
$response = curl_exec($ch); | ||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); | ||
curl_close($ch); | ||
if($httpCode == 202){ | ||
return true; | ||
} else{ | ||
return false; | ||
} | ||
|
||
} | ||
|
||
public function hashPassword($password){ | ||
sebastiansterk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return hash($this->hashAlgo, $password); | ||
} | ||
|
||
public function checkPassword($uid, $password){ | ||
if(isset($uid) | ||
&& isset($password)) { | ||
|
||
$authenticationStatus = $this->sendUserData($uid, $password); | ||
if ($authenticationStatus) { | ||
$uid = mb_strtolower($uid); | ||
$this->storeUser($uid); | ||
return $uid; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why manual curl and not \OCP\Http\Client\IClientService? Raw curl won't work with Nextcloud's configured HTTP proxies and some other things by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any example or documentation about how to use \OCP\Http\Client\IClientService? Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No docs unfortunately nextcloud/documentation#2196 but you can take https://github.com/nextcloud/mail/blob/e8c4120f691591949baf664fc50f7947b55f9582/lib/Service/Avatar/Downloader.php as reference.