You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sc...@apache.org on 2016/07/25 16:25:53 UTC
airavata-php-gateway git commit: adding configurable oauth grant flow
Repository: airavata-php-gateway
Updated Branches:
refs/heads/develop 4ef0b3343 -> eeb86689d
adding configurable oauth grant flow
Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/eeb86689
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/eeb86689
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/eeb86689
Branch: refs/heads/develop
Commit: eeb86689dbe23ee2d837685e65c25219ccacae95
Parents: 4ef0b33
Author: scnakandala <su...@gmail.com>
Authored: Mon Jul 25 12:25:42 2016 -0400
Committer: scnakandala <su...@gmail.com>
Committed: Mon Jul 25 12:25:42 2016 -0400
----------------------------------------------------------------------
app/config/pga_config.php.template | 5 ++
app/controllers/AccountController.php | 134 +++++++++++++----------------
app/routes.php | 2 +-
3 files changed, 66 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/eeb86689/app/config/pga_config.php.template
----------------------------------------------------------------------
diff --git a/app/config/pga_config.php.template b/app/config/pga_config.php.template
index fe8316f..b63f1e6 100644
--- a/app/config/pga_config.php.template
+++ b/app/config/pga_config.php.template
@@ -49,6 +49,11 @@ return array(
'oauth-client-secret' => 'KNTf_LPLuGBDbRVZwkrP_fF5z2Ea',
/**
+ * OAuth Grant Type (password or authorization_code)
+ */
+ 'oauth-grant-type' => 'authorization_code',
+
+ /**
* Identity server domain
*/
'server' => 'idp.scigap.org',
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/eeb86689/app/controllers/AccountController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index 601ad8e..4e061d3 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -47,19 +47,6 @@ class AccountController extends BaseController
->withInput(Input::except('password', 'password_confirm'))
->with("username_exists", true);
} else {
-// We are using account confirmation now
-// WSIS::addUser($username, $password);
-//
-// //update user profile
-// WSIS::updateUserProfile($username, $email, $first_name, $last_name);
-//
-// CommonUtilities::print_success_message('New user created!');
-//
-// if(Config::get('pga_config.wsis')['auth-mode']=="oauth"){
-// return View::make('home');
-// }else{
-// return View::make('account/login');
-// }
WSIS::registerUserAccount($username, $password, $email, $first_name, $last_name, $organization, $address, $country, $telephone, $mobile, $im, $url,
Config::get('pga_config.wsis')['tenant-domain']);
@@ -90,16 +77,15 @@ class AccountController extends BaseController
public function loginView()
{
-// if(Config::get('pga_config.wsis')['auth-mode'] == "oauth"){
-// $url = WSIS::getOAuthRequestCodeUrl();
-// return Redirect::away($url);
-// }else{
-// return View::make('account/login');
-// }
- if(CommonUtilities::id_in_session()){
- return Redirect::to("home");
- }else
- return View::make('account/login');
+ if(Config::get('pga_config.wsis')['oauth-grant-type'] == "authorization_code"){
+ $url = WSIS::getOAuthRequestCodeUrl();
+ return Redirect::away($url);
+ }else{
+ if(CommonUtilities::id_in_session()){
+ return Redirect::to("home");
+ }else
+ return View::make('account/login');
+ }
}
public function loginSubmit()
@@ -171,57 +157,57 @@ class AccountController extends BaseController
}
-// public function oauthCallback()
-// {
-// if (!isset($_GET["code"])) {
-// return Redirect::to('home');
-// }
-//
-// $code = $_GET["code"];
-// $response = WSIS::getOAuthToken($code);
-// if(!isset($response->access_token)){
-// return Redirect::to('home');
-// }
-//
-// $accessToken = $response->access_token;
-// $refreshToken = $response->refresh_token;
-// $expirationTime = time() + $response->expires_in - 5; //5 seconds safe margin
-//
-// $userProfile = WSIS::getUserProfileFromOAuthToken($accessToken);
-// $username = $userProfile['username'];
-//
-// //Fixme - OpenID profile takes some time to get synced (WSO2 IS Issue)
-// //$userRoles = $userProfile['roles'];
-// $userRoles = (array)WSIS::getUserRoles($username);
-//
-// $username = $userProfile['username'];
-//
-// $authzToken = new Airavata\Model\Security\AuthzToken();
-// $authzToken->accessToken = $accessToken;
-// $authzToken->claimsMap = array('userName'=>$username);
-// Session::put('authz-token',$authzToken);
-// Session::put('oauth-refresh-code',$refreshToken);
-// Session::put('oauth-expiration-time',$expirationTime);
-// Session::put("user-profile", $userProfile);
-//
-// if (in_array(Config::get('pga_config.wsis')['admin-role-name'], $userRoles)) {
-// Session::put("admin", true);
-// }
-// if (in_array(Config::get('pga_config.wsis')['read-only-admin-role-name'], $userRoles)) {
-// Session::put("admin-read-only", true);
-// }
-// if (in_array(Config::get('pga_config.wsis')['user-role-name'], $userRoles)) {
-// Session::put("authorized-user", true);
-// }
-//
-// CommonUtilities::store_id_in_session($username);
-// Session::put("gateway_id", Config::get('pga_config.airavata')['gateway-id']);
-//
-// if(Session::get("admin") || Session::get("admin-read-only") || Session::get("authorized-user")){
-// return $this->initializeWithAiravata($username);
-// }
-// return Redirect::to("home");
-// }
+ public function oauthCallback()
+ {
+ if (!isset($_GET["code"])) {
+ return Redirect::to('home');
+ }
+
+ $code = $_GET["code"];
+ $response = WSIS::getOAuthToken($code);
+ if(!isset($response->access_token)){
+ return Redirect::to('home');
+ }
+
+ $accessToken = $response->access_token;
+ $refreshToken = $response->refresh_token;
+ $expirationTime = time() + $response->expires_in - 5; //5 seconds safe margin
+
+ $userProfile = WSIS::getUserProfileFromOAuthToken($accessToken);
+ $username = $userProfile['username'];
+
+ //Fixme - OpenID profile takes some time to get synced (WSO2 IS Issue)
+ //$userRoles = $userProfile['roles'];
+ $userRoles = (array)WSIS::getUserRoles($username);
+
+ $username = $userProfile['username'];
+
+ $authzToken = new Airavata\Model\Security\AuthzToken();
+ $authzToken->accessToken = $accessToken;
+ $authzToken->claimsMap = array('userName'=>$username);
+ Session::put('authz-token',$authzToken);
+ Session::put('oauth-refresh-code',$refreshToken);
+ Session::put('oauth-expiration-time',$expirationTime);
+ Session::put("user-profile", $userProfile);
+
+ if (in_array(Config::get('pga_config.wsis')['admin-role-name'], $userRoles)) {
+ Session::put("admin", true);
+ }
+ if (in_array(Config::get('pga_config.wsis')['read-only-admin-role-name'], $userRoles)) {
+ Session::put("admin-read-only", true);
+ }
+ if (in_array(Config::get('pga_config.wsis')['user-role-name'], $userRoles)) {
+ Session::put("authorized-user", true);
+ }
+
+ CommonUtilities::store_id_in_session($username);
+ Session::put("gateway_id", Config::get('pga_config.airavata')['gateway-id']);
+
+ if(Session::get("admin") || Session::get("admin-read-only") || Session::get("authorized-user")){
+ return $this->initializeWithAiravata($username);
+ }
+ return Redirect::to("home");
+ }
private function initializeWithAiravata($username){
//Check Airavata Server is up
http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/eeb86689/app/routes.php
----------------------------------------------------------------------
diff --git a/app/routes.php b/app/routes.php
index a574d21..fb2302b 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -24,7 +24,7 @@ Route::post("login", "AccountController@loginSubmit");
Route::get("account/dashboard", "AccountController@dashboard");
-//Route::get("callback-url", "AccountController@oauthCallback");
+Route::get("callback-url", "AccountController@oauthCallback");
Route::get("logout", "AccountController@logout");