Saturday, 28 May 2016

An Introduction of OAuth 2.0

Introduction

OAuth 2 is an authorization framework that enables applications to obtain limited access to user accounts on an HTTP service, such as Facebook, GitHub. It works by delegating user authentication to the service that hosts the user account, and authorizing third-party applications to access the user account. OAuth 2 provides authorization flows for web and desktop applications, and mobile devices.

This informational guide is geared towards application developers, and provides an overview of OAuth 2 roles, authorization grant types, use cases, and flows.

OAuth Roles

OAuth defines four roles:
  1.     Resource Owner
  2.     Client
  3.     Resource Server
  4.     Authorization Server

 Resource Owner: User

The resource owner is the user who authorizes an application to access their account. The application's access to the user's account is limited to the "scope" of the authorization granted (e.g. read or write access).

Resource / Authorization Server: API

The resource server hosts the protected user accounts, and the authorization server verifies the identity of the user then issues access tokens to the application.

From an application developer's point of view, a service's API fulfills both the resource and authorization server roles. 

The client is the application that wants to access the user's account. Before it may do so, it must be authorized by the user, and the authorization must be validated by the API.

Friday, 11 March 2016

Creating a Dynamic Variable Name(Variable Variables)

Use PHP's variable variable syntax by assign a $ to a variable whose value is the variable name you want:

<?php
 $a = "Hello";
$hello = "Hello Everyone";
echo $$a."<br/>";
?>

Output: Hello Everyone

Discussion:

The previous example prints Hello Everyone. Because $a = 'hello', $$a is $hello.

Using curly braces, you can construct more complicated expressions that indicate variable names: 

$stooges = array('Moe','Larry','Curly');
$stooge_moe = 'Moses Horwitz';
$stooge_larry = 'Louis Feinberg';
$stooge_curly = 'Jerome Horwitz';

foreach ($stooges as $s) {
  print "$s's real name was ${'stooge_'.strtolower($s)}.\n";
}
Moe's real name was Moses Horwitz.
Larry's real name was Louis Feinberg.
Curly's real name was Jerome Horwitz.