https://github.com/alexbilbie/CodeIgniter-OAuth-2.0-Server
I have found this on GitHub however the steps to implement don't really help with installing the OAuth code into CodeIgniter and haven't found any really good articles on how to do this
Has anyone already done this that can offer me help setting this up?
Hé Hoang,
The oAuth library isn't really self explanatory. This is how I got it working:
Basics
Do a request
Now you want to perform an Authorization Request as a client. These few easy steps are documented in this section.
Edit: Philsturgeon's oAuth 2.0 authorization library could be used to automate this. Described here is the manual way.
For the library, this means going to:
/index.php/oauth?client_id=IN_YOUR_APPLICATION&redirect_uri=IN_YOUR_APPLICATION&response_type=code&scope=YOUR_ROLE
Fill in the variabels with the data you've putten in the database.
Debug some of the error's it might give..
If all goes well you dit the following:
Sign in -> Authorize application -> See you redirect_uri page with ?code=XXXXXXX
You'll want that XXXXXXX code
Then on the redirect_uri make a post to /index.php/oauth/access_token
With these variabels (you know them all now)
That post returns a JSON string containing the access_token (or an error). YEAH!
What's next
Save the access_token in you actual application and use it in requests. On your resource server (probably an API and the same CodeIgniter project as the Authorization server I just explained) you need to validate the access_token before returning results.
This works like this:
$this->load->library('oauth_resource_server');
if (!$this->oauth_resource_server->has_scope(array('account.basic')))
{
// Error logic here - "access token does not have correct permission"
show_error('An access token is required to request this resource.');
}
else
{
//GO RETURN RESULTS
}
Hope this gets you up and running!
PS: You need to build some admin area to manage applications, sessions and roles yourself though.
Eric
I used another spark library that is really good to use with codeigniter. here is the good tutorial on how to install this with spark and use it. Oauth tutorial for codeigniter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With