Monday, October 3, 2016

How to setup OAuth 2.0 server using Apigility?

Software required 

- apigility 1.5
- composer version 1.2.0
- git version 2.10.0

Installation steps
  • Assume apigility has been upgraded to version 1.5 by executing the command below. Version before 1.5 is buggy
 composer update  
[APIGILITY_HOME] is your apigility installation home folder
  •  Launch your APIGILITY admin module, click on "Authentication" menu to launch the configuration page. Click "New adapter" button to launch the adapter configuration page.
  • Fill in the info as shown in the screenshot below, click on "Save" button to create adapter.

  •  Ensure the Status API authentication type is set to the newly created adapter, "oauth2".



 http://apigility/oauth/authorize?response_type=code&client_id=testclient&redirect_uri=/oauth/receivecode&state=xyz   
  • Approval page is displayed as shown in the screen below

  • Once the "testclient" is approved, an authentication code is generated.

  • Use postman with the configuration as shown in the screenshot below, generated access_token to access the API


  • Call the "status" api and "ping" services with the access_token as shown in the screenshot below.

Public Clients
  • client_secret value is omitted for this case. User ID, password and client_id is required. grant_type = "password" is used. Please refer to the screenshot below

Application Access

  • This is used for machine to machine integration. client_id and client_secret are required. grant_type = "client_credentials" is used. Please refer to the screenshot below

    Sunday, September 11, 2016

    How to fix "Error on rename of mysql frm due to permission denied" error message on mysql?

    Try to integrate "lucadegasperi", an OAuth  component on my application recently, I was required to patch the database by running the given patch script. I encountered error message as shown below when run the patch script.

    C:\wamp\www\lumen>php artisan migrate --seed
    Migration table created successfully.
    
    
      [Illuminate\Database\QueryException]
      SQLSTATE[HY000]: General error: 7 Error on rename of '.\[DATABASE_NAME]\#sql-2f6
      c_6.frm' to '.\[DATABASE_NAME]\oauth_session_scopes.frm' (Errcode: 13 - Permissi
      on denied) (SQL: alter table `oauth_session_scopes` add index `oauth_sessio
      n_scopes_session_id_index`(`session_id`))
    
    
    
      [PDOException]
      SQLSTATE[HY000]: General error: 7 Error on rename of '.\[DATABASE_NAME]\#sql-2f6
      c_6.frm' to '.\[DATABASE_NAME]\oauth_session_scopes.frm' (Errcode: 13 - Permissi
      on denied)
    

    I was using a superuser account to connect to mysql database. Should not prompt this error message

    Solution

    • The root cause is the Mcafee antivirus on my Windows 10 stop the MySql to edit the FRM file when "alter" command is executed.
    •  In order to run the patch script, I temporary turn off the real time scanning on my Mcafee. Launch Mcafee and click on "Virus and Spyware protection" option.
    • Select "Real-Time Scanning"option and turn off the "Real-Time scanning" option.

    • Rerun the command "php artisan migrate --seed", all tables was created successfully.

    Saturday, September 3, 2016

    How to configure com_api with Joomla?

    Software required (Assume Joomla is installed)
    - Joomla version 3.6.2
    - com_api plugin (ac_api_installer_v1.8.5.zip)

    Installation steps

    • Login into admin console, click on "Extensions" → "Manage" → "Install" menu

    • Upload extension zip file to install the plugin.
    • Click on "Components" → "Api" → "API Keys", click on "New" button at "API Keys" page to launch "Add New Key" page

    • Click "User" button to add an user, click "Save & Close" button to dismiss the page. API key for the selected user is generated.

    • . Source code below is use to call "users" api from com_api, response in json format is returned
    • <?php
      
      $url="http://localhost/home/index.php?option=com_api&format=raw&app=users&resource=users&key=08a3ffdf9243bc883849e689c3749293"; 
      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_HEADER, false);
      curl_setopt($ch, CURLOPT_NOBODY, false);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      
      $resp = curl_exec($ch);
      print_r($resp);
      
      // Close request to clear up some resources
      curl_close($ch);
      
    • Source code below is use to call "login" api from com_api, response in json format is returned
    • <?php
      $url="http://localhost/home/index.php?option=com_api&format=raw&app=users&resource=login&key=08a3ffdf9243bc883849e689c3749293"; 
      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_HEADER, false);
      curl_setopt($ch, CURLOPT_NOBODY, false);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_exec($ch);
      
      $html = curl_exec($ch);
      print_r($html);
      
      curl_close($ch);
      
      

    • Source code below is use to call "config" api from com_api, response in json format is returned
    • <?php
      
      $url="http://localhost/home/index.php?option=com_api&format=raw&app=users&resource=config&key=08a3ffdf9243bc883849e689c3749293"; 
      
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_HEADER, false);
      curl_setopt($ch, CURLOPT_NOBODY, false);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_exec($ch);
      $html = curl_exec($ch);
      
      print_r($html);
      
      curl_close($ch);
      



    Sunday, August 14, 2016

    How to configure gmail SMTP in Joomla?

    Configure Gmail SMTP details

    • Login as "Administrator", click on "System" → "Global Configuration" menu. Click on "Server" submenu.

    • Fill in the details as shown below
    1. Send Mail: YES
    2. Disable Mass Mail: YES
    3. From email: [Your Gmail Accout]
    4. From Name: [Your Name]
    5. Mailer: SMTP
    6. SMTP Host: smtp.gmail.com
    7. SMTP Port 465
    8. SMTP Security: SSL/TLS
    9. SMTP Authentiation: YES
    10. SMTP Username: [Your Gmail Username]
    11. SMTP Password: [Your Gmail Password]
    • Make sure the extension=php_openssl.dll is enabled at php.ini
    • Click on "Send Test Mail" button to test the mail is delivered.

    Saturday, August 13, 2016

    How to hide and show menu based on user group in Joomla?

    In order to show restricted menus to logged in user, below are the steps and configuration required

    Create new "User Group"
    • Login as "Administrator", click on "Users" → "Groups" → "Add New Groups" menu. Add a new group with the name as "Custom".


    • Add user to the user group, for example, "user1" to "Custom" group.
    • Click on "System" → "Global Configuration" menu. Select "Permissions" tab, ensure "Custom" group "Site Login" action is set to "Allowed".



    Create New Access Level

    • Click on "Users" → "Access Levels" → "Add New Access Level" menu. Add new level details as "Custom Level", select "Custom" user group.

    Configure "Menu" access control
    • Click on "Menus" → "All Menu Items" menu, select a menu item "About Us" and assign the "Access" value to "Custom Level".

       
    • Assign 2 menu items as "Custom Level"

    Verify the behaviour
    • Before login as "user1", launch the page, 2 menu items are displayed
    • Login as "user1", 4 menu items are displayed