GithubHelp home page GithubHelp logo

ziyun / codeigniter-oauth-2.0-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wagner-palombo/codeigniter-oauth-2.0-server

0.0 1.0 0.0 113 KB

An implementation of an OAuth 2.0 authorisation server, resource server, and client

codeigniter-oauth-2.0-server's Introduction

CodeIgniter OAuth 2.0 server

This is an implementation of an OAuth 2.0 (draft 23) authorisation server using the CodeIgniter PHP framework.

Supported features

  • Flows
    • Authorisation code
  • Auto approve applications
  • Users can manage OAuth permissions

How to use

  1. Put the Oauth controller in your controllers directory
  2. Put you Oauth_server library in your libraries directory
  3. Run the auth_server.sql file in the SQL folder to generate the new tables
  4. Create some scopes in the scopes database table. Scopes are permissions to access different datasets. For example if you have an API method that exposes a user's details you may have a scope of user.details, and if you want clients to be able to update the user's details you could have an additional scope of user.update.
  5. Create an application in the applications table. You may want to extend it and create a controller to allow users to register applications.
  6. In the oauth_server library, rewrite the validate_user() function code to allow users to sign in. The function should return a user ID as a string if the username and password are valid or FALSE if not.
  7. In your API controller, for each function that requires OAuth authenticated access enter the following code:
	function user_get($id)
	{
		$this->load->library('oauth_resource_server');
		if ( ! $this->oauth_resource_server->has_scope(array('user.details', 'another.scope')))
		{
			// Error logic here - "access token does not have correct permission to user this API method"
		}
	
		// API code here
	}

If an access token successfully validates then you can use the following methods to convert the access token to a user ID:

	$this->oauth_resource_server->is_user();
	// returns the user's ID or FALSE

Or to convert the access token to an application ID (if you allow anonomous access tokens):

	$this->oauth_resource_server->is_anon();
	// returns the application ID or FALSE

codeigniter-oauth-2.0-server's People

Contributors

alexbilbie avatar jamesbeith avatar rsw686 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.