Skip to content

Instantly share code, notes, and snippets.

@azhurb
Created April 1, 2016 09:49
Show Gist options
  • Save azhurb/4930bb2f167be86fd32e5e3a9620ef23 to your computer and use it in GitHub Desktop.
Save azhurb/4930bb2f167be86fd32e5e3a9620ef23 to your computer and use it in GitHub Desktop.
Demo auth
Index: server/lib/oauth/authaccesshandler.class.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- server/lib/oauth/authaccesshandler.class.php (revision c9ff739911a4ad294cc9b2211123e85a97af3e8b)
+++ server/lib/oauth/authaccesshandler.class.php (revision )
@@ -116,23 +116,31 @@
public function generateUniqueToken(\User $user){
- $token = $user->getId().'.'.md5(microtime(1));
-
$token_record = Mysql::getInstance()->from('access_tokens')->where(array('uid' => $user->getId()))->get()->first();
+ if (empty($token_record)){
+
+ $token = $user->getId().'.'.md5(microtime(1));
+
- $data = array(
- 'uid' => $user->getId(),
- 'token' => $token,
- 'refresh_token' => md5($token.''.uniqid()),
- 'secret_key' => md5($token.microtime(1)),
- 'started' => 'NOW()',
- 'expires' => date('Y-m-d H:i:s', time() + $this->token_expire)
- );
+ $data = array(
+ 'uid' => $user->getId(),
+ 'token' => $token,
+ 'refresh_token' => md5($token.''.uniqid()),
+ 'secret_key' => md5($token.microtime(1)),
+ 'started' => 'NOW()',
+ 'expires' => date('Y-m-d H:i:s', time() + $this->token_expire)
+ );
- if (empty($token_record)){
$result = Mysql::getInstance()->insert('access_tokens', $data)->insert_id();
}else{
- $result = Mysql::getInstance()->update('access_tokens', $data, array('uid' => $user->getId()));
+ $result = Mysql::getInstance()->update('access_tokens',
+ array(
+ 'started' => 'NOW()',
+ 'expires' => date('Y-m-d H:i:s', time() + $this->token_expire)
+ ),
+ array('uid' => $user->getId())
+ );
+ $token = $token_record['token'];
}
if (!$result){
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment