Toggle navigation
Toggle navigation
This project
Loading...
Sign in
UT
/
oauth_2-0_client_php
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
bashofmann
2010-08-10 15:11:00 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9ead0357d5854d77ebbc9b18a56f84fece35e8bd
9ead0357
1 parent
fc6efe78
added readme and example
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
0 deletions
README.md
example.php
README.md
0 → 100644
View file @
9ead035
OAuth 2.0 client library PHP
============================
This PHP library helps you to implement an OAuth 2.0 client.
It uses the draft 10 of the current OAuth 2.0 specification
[
1
]
Currently only the web_server flow is and the core response_type is supported.
Example
-------
An example implementation is available in example.php
License
-------
Copyright (c) 2010 VZnet Netzwerke Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
[
1
]:
http://tools.ietf.org/html/draft-ietf-oauth-v2-10
\ No newline at end of file
...
...
example.php
0 → 100644
View file @
9ead035
<?php
require_once
'oauth2.php'
;
// configuration of client credentials
$client
=
new
OAuth2_Client
(
'CLIENT_ID'
,
'CLIENT_SECRET'
,
'CALLBACK_URL'
);
// configuration of service
$configuration
=
new
OAuth2_Service_Configuration
(
'AUTHORIZE_ENDPOINT'
,
'ACCESS_TOKEN_ENDPOINT'
);
// storage class for access token, just extend OAuth2_DataStore_Abstract for
// your own implementation
$dataStore
=
new
OAuth2_DataStore_Session
();
$scope
=
null
;
$service
=
new
OAuth2_Service
(
$client
,
$configuration
,
$dataStore
,
$scope
);
if
(
isset
(
$_GET
[
'action'
]))
{
switch
(
$_GET
[
'action'
])
{
case
'authorize'
:
// redirects to authorize endpoint
$service
->
authorize
();
break
;
case
'requestApi'
:
// calls api endpoint with access token
echo
$service
->
callApiEndpoint
(
'API_ENDPOINT'
);
break
;
}
}
if
(
isset
(
$_GET
[
'code'
]))
{
// retrieve access token from endpoint
$service
->
getAccessToken
();
}
$token
=
$dataStore
->
retrieveAccessToken
();
?>
<html>
<head>
<script
type=
"text/javascript"
src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
></script>
</head>
<body>
Consumer Key:
<input
type=
"text"
id=
"consumer-key"
value=
"
<?=
$client
->
getClientKey
()
?>
"
/><br
/>
Consumer Secret:
<input
type=
"text"
id=
"consumer-secret"
value=
"
<?=
$client
->
getClientSecret
()
?>
"
/><br
/>
Access Token:
<input
type=
"text"
id=
"access-token"
value=
"
<?=
$token
->
getAccessToken
()
?>
"
/><br
/>
Refresh Token:
<input
type=
"text"
id=
"refresh-token"
value=
"
<?=
$token
->
getRefreshToken
()
?>
"
/><br
/>
LifeTime:
<input
type=
"text"
id=
"lifetime"
value=
"
<?=
$token
->
getLifeTime
()
?>
"
/><br
/>
<br
/>
<a
href=
"javascript:;"
id=
"authorize"
>
authorize
</a><br
/>
<br
/>
<a
href=
"javascript:;"
id=
"request-api"
>
request API
</a><br
/>
<script
type=
"text/javascript"
>
$
(
'#authorize'
).
click
(
function
()
{
window
.
location
.
href
=
'index.php?action=authorize'
;
});
$
(
'#request-api'
).
click
(
function
()
{
window
.
location
.
href
=
'index.php?action=requestApi'
;
});
</script>
</body>
</html>
\ No newline at end of file
...
...
Please
register
or
login
to post a comment