Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]Add Guild Wars 2 Oauth authentification #163

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions config/cnf/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ cnf = {
* hybrid auth config
*/
"hybrid_auth" : {
"callback_url" : "http://4gsd.localtunnel.com/hybridauth",
"google_id" : "",
"google_secret" : "",
"facebook_id" : "",
"facebook_secret" : "",
"twitter_key" : "",
"twitter_secret" : ""
"callback_url" : "http://localhost:8080/hybridauth",
"google_id" : "",
"google_secret" : "",
"facebook_id" : "",
"facebook_secret" : "",
"twitter_key" : "",
"twitter_secret" : "",
"guildwars_key" : "",
"guildwars_secret" : ""
},

/*
Expand Down
13 changes: 9 additions & 4 deletions config/hybridauth-config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

/*!
* HybridAuth
Expand Down Expand Up @@ -34,12 +34,12 @@
"keys" => array ( "id" => getAppConfig("hybrid_auth.google_id"), "secret" => getAppConfig("hybrid_auth.google_secret")),
"scope" => implode(" ", array("https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email")),
"access_type" => "online",
"access_type" => "online",
),

"Facebook" => array (
"enabled" => true,
"keys" => array ( "id" => getAppConfig("hybrid_auth.facebook_id"), "secret" => getAppConfig("hybrid_auth.facebook_secret")),
"keys" => array ( "id" => getAppConfig("hybrid_auth.facebook_id"), "secret" => getAppConfig("hybrid_auth.facebook_secret")),
"scope" => "email, user_about_me, user_birthday",
),

Expand Down Expand Up @@ -68,10 +68,15 @@
"enabled" => false,
"keys" => array ( "id" => "", "secret" => "" )
),

"GuildWars" => array (
"enabled" => true,
"keys" => array ( "id" => getAppConfig("hybrid_auth.guildwars_key"), "secret" => getAppConfig("hybrid_auth.guildwars_secret"))
)
),

// if you want to enable logging, set 'debug_mode' to true then provide a writable file by the web server on "debug_file"
"debug_mode" => false,
"debug_mode" => true,

"debug_file" => "/tmp/hauth.log"
);
3 changes: 3 additions & 0 deletions templates/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<a href="{{ path('social_login', {'provider': 'google'}) }}" class="btn btn-large">
<i class="icon-google-plus"></i>
</a>
<a href="{{ path('social_login', {'provider': 'guildwars'}) }}" class="btn btn-large">
<i class="icon-guildwars2"></i>
</a>
</div>
</div>
</div>
Expand Down
47 changes: 47 additions & 0 deletions vendor/hybridauth/Hybrid/Providers/GuildWars.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Created by PhpStorm.
* User: keneanung
* Date: 09/03/15
* Time: 21:54
*/

class Hybrid_Providers_GuildWars extends Hybrid_Provider_Model_OAuth2 {

/**
* @var string default scopes
*/
public $scope = "account offline";

/**
* IDp wrappers initializer
*/
function initialize()
{
parent::initialize();

// Provider api end-points
$this->api->authorize_url = "https://account.guildwars2.com/oauth2/authorization";
$this->api->token_url = "https://account.guildwars2.com/oauth2/token";
$this->api->curl_authenticate_method = "GET";
}

function getUserProfile()
{
// refresh tokens if needed
$this->refreshToken();

// ask api for user info
$response = $this->api->api("https://api.guildwars2.com/v2/account", "GET", array(), array("Authorization: Bearer {$this->api->access_token}"));

if (!isset($response->id) || isset($response->error)) {
throw new Exception("User profile request failed! {$this->providerId} returned an invalid response.", 6);
}

$profile = new Hybrid_User_Profile();
$profile->identifier = $response->id;
$profile->displayName = $response->name;
$profile->email = $response->name . "@guildwars.com";
return $profile;
}
}
25 changes: 18 additions & 7 deletions vendor/hybridauth/Hybrid/thirdparty/OAuth/OAuth2Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function authenticated()
/**
* Format and sign an oauth for provider api
*/
public function api( $url, $method = "GET", $parameters = array() )
public function api( $url, $method = "GET", $parameters = array(), $additional_headers = array() )
{
if ( strrpos($url, 'http://') !== 0 && strrpos($url, 'https://') !== 0 ) {
$url = $this->api_base_url . $url;
Expand All @@ -132,8 +132,8 @@ public function api( $url, $method = "GET", $parameters = array() )
$response = null;

switch( $method ){
case 'GET' : $response = $this->request( $url, $parameters, "GET" ); break;
case 'POST' : $response = $this->request( $url, $parameters, "POST" ); break;
case 'GET' : $response = $this->request( $url, $parameters, "GET", $additional_headers ); break;
case 'POST' : $response = $this->request( $url, $parameters, "POST", $additional_headers ); break;
}

if( $response && $this->decode_json ){
Expand Down Expand Up @@ -180,13 +180,14 @@ public function refreshToken( $parameters = array() )
$params[$k] = $v;
}

$response = $this->request( $this->token_url, $params, "POST" );
$response = $this->request( $this->token_url, $params, "POST",
array( "Content-Type: application/x-www-form-urlencoded" ) );
return $this->parseRequestResult( $response );
}

// -- utilities

private function request( $url, $params=false, $type="GET" )
private function request( $url, $params=array(), $type="GET", $additional_headers = array() )
{
Hybrid_Logger::info( "Enter OAuth2Client::request( $url )" );
Hybrid_Logger::debug( "OAuth2Client::request(). dump request params: ", serialize( $params ) );
Expand All @@ -204,21 +205,31 @@ private function request( $url, $params=false, $type="GET" )
curl_setopt($ch, CURLOPT_USERAGENT , $this->curl_useragent );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , $this->curl_connect_time_out );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , $this->curl_ssl_verifypeer );
curl_setopt($ch, CURLOPT_HTTPHEADER , $this->curl_header );
curl_setopt($ch, CURLOPT_HTTPHEADER , array_merge($this->curl_header, $additional_headers) );

curl_setopt($ch, CURLOPT_VERBOSE, true);
$verbose = fopen('php://temp', 'rw+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);

if($this->curl_proxy){
curl_setopt( $ch, CURLOPT_PROXY , $this->curl_proxy);
}

if( $type == "POST" ){
curl_setopt($ch, CURLOPT_POST, 1);
if($params) curl_setopt( $ch, CURLOPT_POSTFIELDS, $params );
if($params) curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($params) );
}

$response = curl_exec($ch);
Hybrid_Logger::debug( "OAuth2Client::request(). dump request info: ", serialize( curl_getinfo($ch) ) );
Hybrid_Logger::debug( "OAuth2Client::request(). dump request result: ", serialize( $response ) );

rewind($verbose);
$verboseLog = stream_get_contents($verbose);
Hybrid_Logger::debug( "OAuth2Client::request(). dump verbose curl: ", $verboseLog );
fclose($verbose);


$this->http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->http_info = array_merge($this->http_info, curl_getinfo($ch));

Expand Down