Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
e-epal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Χάρης Παπαδόπουλος
e-epal
Commits
66ebf312
Commit
66ebf312
authored
Feb 13, 2017
by
Χάρης Παπαδόπουλος
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created new oauthost module
parent
91b3df4d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
360 additions
and
3 deletions
+360
-3
.gitignore
.gitignore
+1
-0
drupal/modules/oauthost/composer.json
drupal/modules/oauthost/composer.json
+14
-0
drupal/modules/oauthost/oauthost.info.yml
drupal/modules/oauthost/oauthost.info.yml
+5
-0
drupal/modules/oauthost/oauthost.module
drupal/modules/oauthost/oauthost.module
+36
-0
drupal/modules/oauthost/oauthost.services.yml
drupal/modules/oauthost/oauthost.services.yml
+7
-0
drupal/modules/oauthost/src/Authentication/Provider/OSTAuthenticationProvider.php
...src/Authentication/Provider/OSTAuthenticationProvider.php
+225
-0
drupal/modules/oauthost/src/Tests/LoadTest.php
drupal/modules/oauthost/src/Tests/LoadTest.php
+46
-0
drupal/modules/oauthost/templates/oauthost.html.twig
drupal/modules/oauthost/templates/oauthost.html.twig
+1
-0
source/services/helper-data-service.ts
source/services/helper-data-service.ts
+25
-3
No files found.
.gitignore
View file @
66ebf312
...
...
@@ -6,6 +6,7 @@ drupal/*
drupal/modules/*
!drupal/modules/epal/
!drupal/modules/epalreadydata/
!drupal/modules/oauthost/
# Logs
*.log
...
...
drupal/modules/oauthost/composer.json
0 → 100644
View file @
66ebf312
{
"name"
:
"drupal/oauthost"
,
"type"
:
"drupal-module"
,
"description"
:
"Authentication Provider OST"
,
"keywords"
:
[
"Drupal"
],
"license"
:
"GPL-2.0+"
,
"homepage"
:
"https://www.drupal.org/project/oauthost"
,
"minimum-stability"
:
"dev"
,
"support"
:
{
"issues"
:
"https://www.drupal.org/project/issues/oauthost"
,
"source"
:
"http://cgit.drupalcode.org/oauthost"
},
"require"
:
{
}
}
drupal/modules/oauthost/oauthost.info.yml
0 → 100644
View file @
66ebf312
name
:
oauthost
type
:
module
description
:
Authentication Provider OST
core
:
8.x
package
:
oauthost
drupal/modules/oauthost/oauthost.module
0 → 100644
View file @
66ebf312
<?php
/**
* @file
* Contains oauthost.module.
*/
use
Drupal\Core\Routing\RouteMatchInterface
;
/**
* Implements hook_help().
*/
function
oauthost_help
(
$route_name
,
RouteMatchInterface
$route_match
)
{
switch
(
$route_name
)
{
// Main module help for the oauthost module.
case
'help.page.oauthost'
:
$output
=
''
;
$output
.
=
'<h3>'
.
t
(
'About'
)
.
'</h3>'
;
$output
.
=
'<p>'
.
t
(
'Authentication Provider OST'
)
.
'</p>'
;
return
$output
;
default
:
}
}
/**
* Implements hook_theme().
*/
function
oauthost_theme
()
{
return
[
'oauthost'
=>
[
'template'
=>
'oauthost'
,
'render element'
=>
'children'
,
],
];
}
drupal/modules/oauthost/oauthost.services.yml
0 → 100644
View file @
66ebf312
services
:
authentication.oauthost
:
class
:
Drupal\oauthost\Authentication\Provider\OSTAuthenticationProvider
arguments
:
[
'
@config.factory'
,
'
@entity_type.manager'
]
tags
:
-
{
name
:
authentication_provider
,
provider_id
:
ostauthentication_provider
,
priority
:
100
}
drupal/modules/oauthost/src/Authentication/Provider/OSTAuthenticationProvider.php
0 → 100644
View file @
66ebf312
<?php
namespace
Drupal\oauthost\Authentication\Provider
;
use
Drupal\Core\Authentication\AuthenticationProviderInterface
;
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent
;
use
Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
;
use
Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
;
use
\
OAuthProvider
;
use
\
OAuthException
;
/**
* Class OSTAuthenticationProvider.
*
* @package Drupal\oauthost\Authentication\Provider
*/
class
OSTAuthenticationProvider
implements
AuthenticationProviderInterface
{
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected
$configFactory
;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
$entityTypeManager
;
/**
* The user data service.
*
* @var \Drupal\user\UserDataInterface
*/
protected
$user_data
;
/**
* The logger service for OAuth.
*
* @var \Psr\Log\LoggerInterface
*/
protected
$logger
;
/**
* An authenticated user object.
*
* @var \Drupal\user\UserBCDecorator
*/
protected
$user
;
/**
* Constructor.
*
* @param \Drupal\user\UserDataInterface
* The user data service.
* @param \Psr\Log\LoggerInterface $logger
* The logger service for OAuth.
*/
/* public function __construct(UserDataInterface $user_data, LoggerInterface $logger) {
$this->user_data = $user_data;
$this->logger = $logger;
} */
/**
* Constructs a HTTP basic authentication provider object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public
function
__construct
(
ConfigFactoryInterface
$config_factory
,
EntityTypeManagerInterface
$entity_type_manager
)
{
$this
->
configFactory
=
$config_factory
;
$this
->
entityTypeManager
=
$entity_type_manager
;
}
/**
* Checks whether suitable authentication credentials are on the request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @return bool
* TRUE if authentication credentials suitable for this provider are on the
* request, FALSE otherwise.
*/
public
function
applies
(
Request
$request
)
{
// If you return TRUE and the method Authentication logic fails,
// you will get out from Drupal navigation if you are logged in.
// Only check requests with the 'authorization' header starting with OAuth.
drupal_set_message
(
"sdfsddgdg"
);
return
getHeader
(
$request
,
'OAuthEnabled'
);
// return preg_match('/^OAuth/', $request->headers->get('authorization'));
// return $this->checkAuthToken($this->getAuthToken($request));
}
private
function
checkAuthToken
(
$authToken
)
{
if
(
!
$authToken
)
{
return
TRUE
;
}
else
if
(
$authToken
===
'bourboutsala'
)
{
return
FALSE
;
}
else
{
return
TRUE
;
}
}
private
function
getLoginToken
(
$request
)
{
$loginToken
=
$request
->
headers
->
get
(
'X-Login-Token'
);
if
(
isset
(
$loginToken
)
&&
$loginToken
!==
""
)
{
return
TRUE
;
}
else
{
return
FALSE
;
}
}
private
function
getHeader
(
$request
,
$headerName
)
{
$headerValue
=
$request
->
headers
->
get
(
$headerName
);
if
(
isset
(
$headerValue
)
&&
$headerValue
!==
""
)
{
return
$headerValue
;
}
else
{
return
FALSE
;
}
}
/**
* {@inheritdoc}
*/
/* public function authenticate(Request $request) {
$consumer_ip = $request->getClientIp();
$ips = ['192.168.0.59:80'];
// if (in_array($consumer_ip, $ips)) {
if ($request->query->get('name') === 'haris') {
// Return Anonymous user.
print_r($request->query->get('name'));
return true;
// return $this->entityTypeManager->getStorage('user')->load(1);
}
else {
throw new AccessDeniedHttpException();
}
} */
public
function
authenticate
(
Request
$request
)
{
/* $code = filter_input(INPUT_GET, 'code');
if (empty($code) || !$this->client) {
return new RedirectResponse('/');
}
try {
$this->client->authenticate($code);
}
catch (\Exception $e) {
return new RedirectResponse('/');
}
$plus = new Google_Service_Oauth2($this->client);
$userinfo = $plus->userinfo->get();
$user_email = $userinfo['email']; */
drupal_set_message
(
"hello"
);
$user_email
=
'haris.rnd@gmail.com'
;
$user
=
user_load_by_mail
(
$user_email
);
/* if (!$user) {
$user_name = $userinfo['name'];
$user_picture = $userinfo['picture'];
try {
$user = User::create([
'name' => $user_name,
'mail' => $user_email,
'status' => 1,
'picture' => $user_picture,
]);
// hook_google_oauth_create_user_alter($user, $userinfo);
\Drupal::moduleHandler()->alter('google_oauth_create_user', $user, $userinfo);
$user->save();
}
catch (\Exception $e) {
return new RedirectResponse('/');
}
} */
user_login_finalize
(
$user
);
// return new RedirectResponse('http://example.com');
return
(
$user
);
// return $this->redirect('<front>');
}
/**
* {@inheritdoc}
*/
public
function
cleanup
(
Request
$request
)
{}
/**
* {@inheritdoc}
*/
/* public function handleException(GetResponseForExceptionEvent $event) {
$exception = $event->getException();
if ($exception instanceof AccessDeniedHttpException) {
$event->setException(
new UnauthorizedHttpException('Invalid consumer origin.', $exception)
);
return TRUE;
}
return FALSE;
} */
}
drupal/modules/oauthost/src/Tests/LoadTest.php
0 → 100644
View file @
66ebf312
<?php
namespace
Drupal\oauthost\Tests
;
use
Drupal\Core\Url
;
use
Drupal\simpletest\WebTestBase
;
/**
* Simple test to ensure that main page loads with module enabled.
*
* @group oauthost
*/
class
LoadTest
extends
WebTestBase
{
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
[
'oauthost'
];
/**
* A user with permission to administer site configuration.
*
* @var \Drupal\user\UserInterface
*/
protected
$user
;
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
user
=
$this
->
drupalCreateUser
([
'administer site configuration'
]);
$this
->
drupalLogin
(
$this
->
user
);
}
/**
* Tests that the home page loads with a 200 response.
*/
public
function
testLoad
()
{
$this
->
drupalGet
(
Url
::
fromRoute
(
'<front>'
));
$this
->
assertResponse
(
200
);
}
}
drupal/modules/oauthost/templates/oauthost.html.twig
0 → 100644
View file @
66ebf312
<!-- Add you custom twig html here -->
\ No newline at end of file
source/services/helper-data-service.ts
View file @
66ebf312
import
{
Http
,
Headers
}
from
'
@angular/http
'
;
import
{
Http
,
Headers
,
RequestOptions
}
from
'
@angular/http
'
;
import
{
Injectable
}
from
'
@angular/core
'
;
import
{
Observable
}
from
"
rxjs/Observable
"
;
import
'
rxjs/add/operator/map
'
;
...
...
@@ -15,8 +15,19 @@ export class HelperDataService {
constructor
(
private
http
:
Http
)
{
};
getCourseFields
()
{
let
headers
=
new
Headers
({
//"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
// "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
"
Content-Type
"
:
"
application/json
"
,
// "Content-Type": "text/plain", // try to skip preflight
//"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
//"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
"
X-CSRF-Token
"
:
"
LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc
"
,
"
X-Auth-Token
"
:
"
bourboutsala
"
});
let
options
=
new
RequestOptions
({
headers
:
headers
});
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
http
.
get
(
`
${
AppSettings
.
API_ENDPOINT
}
/coursefields/list`
)
this
.
http
.
get
(
`
${
AppSettings
.
API_ENDPOINT
}
/coursefields/list`
,
options
)
.
map
(
response
=>
<
ICourseField
[]
>
response
.
json
())
.
subscribe
(
data
=>
{
resolve
(
data
);
...
...
@@ -45,8 +56,19 @@ export class HelperDataService {
};
getRegionsWithSchools
()
{
let
headers
=
new
Headers
({
//"Authorization": "Basic cmVzdHVzZXI6czNjckV0MFAwdWwwJA==", // encoded user:pass
// "Authorization": "Basic bmthdHNhb3Vub3M6emVtcmFpbWU=",
"
Content-Type
"
:
"
application/json
"
,
// "Content-Type": "text/plain", // try to skip preflight
//"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
//"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
"
X-CSRF-Token
"
:
"
LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc
"
,
"
X-Auth-Token
"
:
"
bourboutsal
"
});
let
options
=
new
RequestOptions
({
headers
:
headers
});
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
http
.
get
(
`
${
AppSettings
.
API_ENDPOINT
}
/regions/list`
)
this
.
http
.
get
(
`
${
AppSettings
.
API_ENDPOINT
}
/regions/list`
,
options
)
.
map
(
response
=>
response
.
json
())
.
subscribe
(
data
=>
{
// console.log(data);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment