Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Törcsvári Gergő
AuthSCH - Client
Commits
666019f5
Commit
666019f5
authored
Jul 18, 2014
by
Zoltán
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
netbeans crying...
parent
63a50990
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
php/AuthSCHClient.class.php
php/AuthSCHClient.class.php
+9
-5
No files found.
php/AuthSCHClient.class.php
View file @
666019f5
...
...
@@ -43,16 +43,18 @@ class AuthSCHClient {
}
public
function
__destruct
()
{
if
(
isset
(
$this
->
tokens
))
if
(
isset
(
$this
->
tokens
))
{
unset
(
$this
->
tokens
);
}
}
private
function
curlExec
(
$urlPart
,
$data
)
{
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
self
::
$host
.
$urlPart
);
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
0
);
if
(
$urlPart
!=
"oauth2/resource"
)
if
(
$urlPart
!=
"oauth2/resource"
)
{
curl_setopt
(
$ch
,
CURLOPT_USERPWD
,
self
::
$username
.
":"
.
self
::
$password
);
}
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
30
);
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
http_build_query
(
$data
));
...
...
@@ -111,15 +113,16 @@ class AuthSCHClient {
$ch
=
$this
->
curlExec
(
"oauth2/token"
,
$data
);
$tokens
=
json_decode
(
$ch
);
if
(
$tokens
===
null
||
!
isset
(
$tokens
->
access_token
)
||
empty
(
$tokens
->
access_token
))
if
(
$tokens
===
null
||
!
isset
(
$tokens
->
access_token
)
||
empty
(
$tokens
->
access_token
))
{
throw
new
Exception
(
"invalid token data"
);
}
$this
->
tokens
->
access_token
=
$tokens
->
access_token
;
}
public
function
getData
()
{
$response
=
@
file_get_contents
(
self
::
$host
.
'api/profile/?access_token='
.
$this
->
tokens
->
access_token
);
if
(
isset
(
$response
)
&&
!
empty
(
$response
))
{
if
(
isset
(
$response
)
&&
$response
!==
false
&&
!
empty
(
$response
))
{
$data
=
json_decode
(
$response
);
if
(
$data
!==
null
)
{
return
$data
;
...
...
@@ -127,8 +130,9 @@ class AuthSCHClient {
throw
new
Exception
(
'invalid json'
);
}
}
else
{
if
(
isset
(
$_SESSION
[
'tokens'
]))
if
(
isset
(
$_SESSION
[
'tokens'
]))
{
unset
(
$_SESSION
[
'tokens'
]);
}
throw
new
Exception
(
'invalid response'
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment