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

Add EVE Online service #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
composer.lock
composer.phar
composer.phar
/nbproject/
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The implementation of the authorization on your own server has several advantage
* VKontake (ru)
* Mail.ru (ru)
* Odnoklassniki (ru)
* EVE Online


### Resources
Expand Down Expand Up @@ -215,7 +216,13 @@ Add the following in your config:
'clientSecret' => '...',
'clientPublic' => '...',
'title' => 'Odnoklas.',
],
],
'eve' => [
// Register application: https://developers.eveonline.com/applications
'class' => 'nodge\eauth\services\EveOnlineOAuth2Service',
'clientId' => '...',
'clientSecret' => '...'
],
],
],

Expand Down
4 changes: 4 additions & 0 deletions src/assets/css/eauth.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@

.eauth-service-id-instagram .eauth-service-link:before {
background-position: 0 -474px;
}

.eauth-service-id-eve .eauth-service-link:before {
background-position: 0 -507px;
}
Binary file modified src/assets/images/auth-src.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/images/auth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
116 changes: 116 additions & 0 deletions src/services/EveOnlineOAuth2Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

/**
* EveOnlineOAuth2Service class file.
*
* Register application: https://developers.eveonline.com/applications
*
* @author Maxim Zemskov <[email protected]>, nek <[email protected]>
* @link http://github.com/Nodge/yii2-eauth/
* @license http://www.opensource.org/licenses/bsd-license.php
*/

namespace nodge\eauth\services;

use \nodge\eauth\oauth2\Service;

class EveOnlineOAuth2Service extends Service {

/**
* @var string
*/
protected $name = 'eve';

/**
* @var string
*/
protected $title = 'EVE Online';

/**
* @var string
*/
protected $type = 'OAuth2';

/**
* @var array
*/
protected $jsArguments = ['popup' => ['width' => 680, 'height' => 500]];

/**
* @var array
*/
protected $providerOptions = [
'authorize' => 'https://login.eveonline.com/oauth/authorize',
'access_token' => 'https://login.eveonline.com/oauth/token'
];


/**
*
*/
protected function fetchAttributes() {
$tokenData = $this->getAccessTokenData();
//
$info = (array) $this->makeSignedRequest('https://login.eveonline.com/oauth/verify', [
'headers' => [
'Authorization'=>'Bearer ' . $tokenData['access_token']
]
]);
//
$this->attributes['id'] = $info['CharacterID'];
$this->attributes['name'] = $info['CharacterName'];
$this->attributes['char_hash'] = $info['CharacterOwnerHash'];

// Set full public character info
$data = $this->getAPIData($info['CharacterID']);
//
$this->attributes['race'] = (string) $data->race;
$this->attributes['bloodline'] = (string) $data->bloodline;
$this->attributes['corporationID'] = (integer) $data->corporationID;
$this->attributes['corporation'] = (string) $data->corporation;
$this->attributes['securityStatus'] = (double) $data->securityStatus;
//
if (isset($data->allianceID)) {
$this->attributes['allianceID'] = (integer) $data->allianceID;
$this->attributes['alliance'] = (string) $data->alliance;
}
}

/**
* Returns the error array.
*
* @param array $response
* @return array the error array with 2 keys: code and message. Should be null if no errors.
*/
protected function fetchResponseError($response) {
if (isset($response['message'])) {
return [
'code' => isset($response['error']) ? $response['code'] : 0,
'message' => $response['message'],
];
} else {
return null;
}
}

/**
* Get data from EVE API
*
* @param integer $charId
* @return SimpleXMLElement
*/
private function getAPIData($charId) {
$options = [
'http' => [
'method' => 'GET',
'user_agent' => 'yii2-eauth (+https://github.com/Nodge/yii2-eauth)'
]
];
$context = stream_context_create($options);
$url = 'https://api.eveonline.com/eve/CharacterInfo.xml.aspx?characterID=' . (int) $charId;
$data = file_get_contents($url, false, $context);
$xml = simplexml_load_string($data);
return $xml->result;
}

}