Friday, August 29, 2014

Get Oauth2 Access & Refresh Token in Apigility (ZF2)

Oauth2 Access & Refresh Token:

For set up of oauth2 go to your config/autoload/local.php and add it in return array

'zf-oauth2' => array(
        'storage' => 'ZF\\OAuth2\\Adapter\\PdoAdapter',
        'db' => array(
            'dsn' => 'mysql:dbname=zend_db;host=localhost;charset=utf8',
            'username' => 'root',
            'password' => 'root',
        ),
        'allow_implicit' => true,
        'enforce_state' => true,
    ),


Set your configuration according to your requirements.

Create your tables accordingly this file

vendor/zfcampus/zf-oauth2/data/db_oauth2.sql

 Insert these fields accordingly your tables

client_id testclient and client_secret testpass, and a user with username testuser and a password testpass.

Password and Client Secret should be in bcrypt form

Now for testing run this in your address bar

http://localhost/oauth/authorize?response_type=code&client_id=testclient&redirect_uri=/oauth/receivecode&state=xyz
 
Now it will show a screen like 


Authorize
Now click on yes.

It will show a screen like

Authentication code
Now run curl command in your terminal with in 30 seconds. It will provide you access and refresh token.

Thanks

No comments:

Post a Comment