First draft of oauthost module. It works for tests. The auth token and role...

First draft of oauthost module. It works for tests. The auth token and role are saved in Redux store
parent c77beea9
oauthost.callback_log_in:
path: /oauth/cb
defaults:
_controller: '\Drupal\oauthost\Controller\CBController::loginCB'
requirements:
_permission: 'access content'
services: services:
authentication.oauthost: authentication.oauthost:
class: Drupal\oauthost\Authentication\Provider\OSTAuthenticationProvider class: Drupal\oauthost\Authentication\Provider\OAuthOSTConsumer
arguments: ['@config.factory', '@entity_type.manager'] arguments: ['@config.factory', '@entity_type.manager', '@logger.channel.oauth']
tags: tags:
- { name: authentication_provider, provider_id: ostauthentication_provider, priority: 100 } - { name: authentication_provider, provider_id: ostauthentication_provider, priority: 100 }
logger.channel.oauth:
parent: 'logger.channel_base'
arguments: ['oauthost']
<?php
namespace Drupal\oauthost\Controller;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
class CBController extends ControllerBase {
protected $query_factory;
protected $entityTypeManager;
protected $request;
protected $logger;
public function __construct(EntityTypeManagerInterface $entityTypeManager, QueryFactory $query_factory) {
$this->entityTypeManager = $entityTypeManager;
$this->query_factory = $query_factory;
$this->request = \Drupal::request();
$this->logger = \Drupal::logger('oauthost');
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('entity.query')
);
}
public function loginCB() {
$authToken = $this->request->query->get('oauth_token');
$authVerifier = $this->request->query->get('oauth_verifier');
$this->logger->notice("authToken=".$authToken."***authVerifier=".$authVerifier);
/* $response = new JsonResponse(['hello' => 'world', 'name' => $name, 'authToken' => $authToken, 'accessKey' => $accessKey]);
$response->headers->set('X-AUTH-TOKEN', 'HELLOTOKEN'); */
return new RedirectResponse('/dist/#/?auth_token=' . $authToken . '&auth_role=student',302,[]);
}
}
...@@ -5,7 +5,8 @@ import { SectorCoursesActions } from './sectorcourses.actions'; ...@@ -5,7 +5,8 @@ import { SectorCoursesActions } from './sectorcourses.actions';
import { StudentDataFieldsActions } from './studentdatafields.actions'; import { StudentDataFieldsActions } from './studentdatafields.actions';
import { EpalClassesActions } from './epalclass.actions'; import { EpalClassesActions } from './epalclass.actions';
import { AmkaFillsActions} from './amkafill.actions'; import { AmkaFillsActions} from './amkafill.actions';
const ACTION_PROVIDERS = [ CourseFieldsActions, SectorFieldsActions, RegionSchoolsActions, SectorCoursesActions, StudentDataFieldsActions, EpalClassesActions, AmkaFillsActions ]; import { LoginInfoActions} from './logininfo.actions';
const ACTION_PROVIDERS = [ CourseFieldsActions, SectorFieldsActions, RegionSchoolsActions, SectorCoursesActions, StudentDataFieldsActions, EpalClassesActions, AmkaFillsActions, LoginInfoActions ];
export { export {
CourseFieldsActions, CourseFieldsActions,
...@@ -15,5 +16,6 @@ export { ...@@ -15,5 +16,6 @@ export {
StudentDataFieldsActions, StudentDataFieldsActions,
EpalClassesActions, EpalClassesActions,
AmkaFillsActions, AmkaFillsActions,
LoginInfoActions,
ACTION_PROVIDERS, ACTION_PROVIDERS,
}; };
import { LOGININFO_SAVE } from '../constants';
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store';
import { HelperDataService } from '../services/helper-data-service';
@Injectable()
export class LoginInfoActions {
constructor(
private _ngRedux: NgRedux<IAppState>,
private _hds: HelperDataService) {}
saveLoginInfo = (loginInfo) => {
return this._ngRedux.dispatch({
type: LOGININFO_SAVE,
payload: {
loginInfo
}
});
};
}
import {Component} from '@angular/core'; import {Router, ActivatedRoute, Params} from '@angular/router';
import {OnInit, Component} from '@angular/core';
import { LoginInfoActions } from '../actions/logininfo.actions';
import { import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
FormControl, FormControl,
FormArray FormArray
} from '@angular/forms'; } from '@angular/forms';
import { AppSettings } from '../app.settings';
@Component({ @Component({
selector: 'home', selector: 'home',
template: ` template: `
<div> <div>
<h4>Στοιχεία Σύνδεσης</h4> <h4>Στοιχεία Σύνδεσης</h4>
<form [formGroup]="formGroup"> <form [formGroup]="formGroup" method = "POST" action="http://eepal.dev/drupal/oauth/login" #form>
<div class="form-group"> <input type="hidden" name="X-oauth-enabled" value="true">
<label for="UserName">Όνομα Χρήστη</label><input class="form-control" type="text" formControlName="Username">
</div>
<div class="form-group">
<label for="Paswd">Κωδικός Ασφαλείας</label><input class="form-control" type="password" formControlName="Paswd">
</div>
<div class="row"> <div class="row">
<div class="col-md-2 col-md-offset-5"> <div class="col-md-2 col-md-offset-5">
<button type="button" class="btn-primary btn-lg pull-center" (click)="checkvalidation()"> <button type="submit" class="btn-primary btn-lg pull-center" (click)="form.submit()">
Συνέχεια<span class="glyphicon glyphicon-menu-right"></span> Είσοδος μέσω TaxisNet<span class="glyphicon glyphicon-menu-right"></span>
</button> </button>
</div> </div>
<div *ngIf="emptyselection==true">
Παρακαλώ συμπληρώστε το ΑΜΚΑ του μαθητή
</div>
</div> </div>
</form> </form>
</div> </div>
` `
}) })
export default class Home { export default class Home implements OnInit{
public formGroup: FormGroup; public formGroup: FormGroup;
constructor(private fb: FormBuilder) { constructor(private fb: FormBuilder,
private _ata: LoginInfoActions,
private activatedRoute: ActivatedRoute) {
this.formGroup = this.fb.group({ this.formGroup = this.fb.group({
Username: [], Username: [],
Paswd : [] Paswd : []
}); });
}; };
ngOnInit() {
// subscribe to router event
this.activatedRoute.queryParams.subscribe((params: Params) => {
let authToken = params['auth_token'];
let authRole = params['auth_role'];
this._ata.saveLoginInfo({auth_token: authToken, auth_role: authRole});
console.log(authToken);
});
}
checkvalidation() { checkvalidation() {
} }
} }
\ No newline at end of file
...@@ -16,6 +16,8 @@ export const STUDENTDATAFIELDS_SAVE = 'STUDENTDATAFIELDS_SAVE'; ...@@ -16,6 +16,8 @@ export const STUDENTDATAFIELDS_SAVE = 'STUDENTDATAFIELDS_SAVE';
export const EPALCLASSES_SAVE = 'EPALCLASSES_SAVE'; export const EPALCLASSES_SAVE = 'EPALCLASSES_SAVE';
export const AMKAFILL_SAVE = 'AMKAFILL_SAVE'; export const AMKAFILL_SAVE = 'AMKAFILL_SAVE';
export const LOGININFO_SAVE = 'LOGININFO_SAVE';
//export const VALID_NAMES_PATTERN = '[Α-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$'; //export const VALID_NAMES_PATTERN = '[Α-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$';
export const VALID_NAMES_PATTERN = '[A-Za-zΑ-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$'; export const VALID_NAMES_PATTERN = '[A-Za-zΑ-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$';
export const VALID_ADDRESS_PATTERN = '[0-9A-Za-zΑ-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$'; export const VALID_ADDRESS_PATTERN = '[0-9A-Za-zΑ-ΩΆΈΉΊΎΌΏα-ωάέήίύόώ ]*$';
......
...@@ -24,6 +24,7 @@ export class HelperDataService { ...@@ -24,6 +24,7 @@ export class HelperDataService {
//"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY" //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
//"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8" //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
"X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc", "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
"X-oauth-enabled": "true",
"X-Auth-Token": "bourboutsala" "X-Auth-Token": "bourboutsala"
}); });
let options = new RequestOptions({ headers: headers }); let options = new RequestOptions({ headers: headers });
...@@ -65,7 +66,8 @@ export class HelperDataService { ...@@ -65,7 +66,8 @@ export class HelperDataService {
//"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY" //"X-CSRF-Token": "hVtACDJjFRSyE4bgGJENHbXY0B9yNhF71Fw-cYHSDNY"
//"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8" //"X-CSRF-Token": "fj1QtF_Z_p6kE19EdCnN08zoSjVfcT4Up-ciW6I0IG8"
"X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc", "X-CSRF-Token": "LU92FaWYfImfZxfldkF5eVnssdHoV7Aa9fg8K1bWYUc",
"X-Auth-Token": "bourboutsal" "X-oauth-enabled": "true",
"X-Auth-Token": "bourboutsala"
}); });
let options = new RequestOptions({ headers: headers }); let options = new RequestOptions({ headers: headers });
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
......
...@@ -7,6 +7,7 @@ import { IRegions, IRegion, IRegionSchool } from './regionschools/regionschools. ...@@ -7,6 +7,7 @@ import { IRegions, IRegion, IRegionSchool } from './regionschools/regionschools.
import { ISectors, ISector, ISectorCourse } from './sectorcourses/sectorcourses.types'; import { ISectors, ISector, ISectorCourse } from './sectorcourses/sectorcourses.types';
import { IStudentDataField, IStudentDataFields } from './studentdatafields/studentdatafields.types'; import { IStudentDataField, IStudentDataFields } from './studentdatafields/studentdatafields.types';
import { IEpalClass, IEpalClasses } from './epalclasses/epalclasses.types'; import { IEpalClass, IEpalClasses } from './epalclasses/epalclasses.types';
import { ILoginInfoToken, ILoginInfo } from './logininfo/logininfo.types';
export { export {
IAppState, IAppState,
...@@ -25,6 +26,7 @@ export { ...@@ -25,6 +26,7 @@ export {
IStudentDataFields, IStudentDataFields,
IEpalClass, IEpalClass,
IEpalClasses, IEpalClasses,
ILoginInfo,
}; };
......
import { ILoginInfoToken, ILoginInfo } from './logininfo.types';
import { loginInfoReducer } from './logininfo.reducer';
import { deimmutifyLoginInfo } from './logininfo.transformers';
export {
ILoginInfoToken,
ILoginInfo,
loginInfoReducer,
deimmutifyLoginInfo,
};
import { List } from 'immutable';
import { ILoginInfoToken } from './logininfo.types';
// export const INITIAL_STATE = List<ICourseField>([new CourseFieldRecord({})]);
export const INITIAL_STATE = List<ILoginInfoToken>();
import { ILoginInfo, ILoginInfoToken } from './logininfo.types';
import { INITIAL_STATE } from './logininfo.initial-state';
import { Seq } from 'immutable';
import {
LOGININFO_SAVE
} from '../../constants';
export function loginInfoReducer(state: ILoginInfo = INITIAL_STATE, action): ILoginInfo {
switch (action.type) {
case LOGININFO_SAVE:
let loginInfoTokens = Array<ILoginInfoToken>();
let ind=0;
state.forEach(loginInfoToken => {
loginInfoTokens.push(<ILoginInfoToken>{auth_token: action.payload.loginInfo.auth_token, auth_role: action.payload.loginInfo.auth_role});
ind++;
});
return Seq(loginInfoTokens).map(n => n).toList();
default: return state;
}
};
import { ILoginInfo, ILoginInfoToken } from './logininfo.types';
export function deimmutifyLoginInfo(state: ILoginInfo): ILoginInfoToken[] {
let fetchedLoginInfoTokens = new Array();
state.forEach(loginInfoToken => {
fetchedLoginInfoTokens.push(<ILoginInfoToken>{auth_token: loginInfoToken.auth_token, auth_role: loginInfoToken.auth_role});
});
return fetchedLoginInfoTokens;
};
import { List } from 'immutable';
export interface ILoginInfoToken {
auth_token: string;
auth_role: string;
}
export type ILoginInfo = List<ILoginInfoToken>;
...@@ -6,6 +6,7 @@ import * as sectors from './sectorcourses'; ...@@ -6,6 +6,7 @@ import * as sectors from './sectorcourses';
import * as studentDataFields from './studentdatafields'; import * as studentDataFields from './studentdatafields';
import * as epalclasses from './epalclasses'; import * as epalclasses from './epalclasses';
import * as amkafills from './amkafill'; import * as amkafills from './amkafill';
import * as loginInfo from './logininfo';
/* /*
* This is where we 'assemble' the full store out of its modules. * This is where we 'assemble' the full store out of its modules.
...@@ -18,7 +19,8 @@ export interface IAppState { ...@@ -18,7 +19,8 @@ export interface IAppState {
sectors?: sectors.ISectors; sectors?: sectors.ISectors;
studentDataFields?: studentDataFields.IStudentDataFields; studentDataFields?: studentDataFields.IStudentDataFields;
epalclasses?: epalclasses.IEpalClasses; epalclasses?: epalclasses.IEpalClasses;
amkafills?: amkafills.IAmkaFills; amkafills?: amkafills.IAmkaFills;
loginInfo?: loginInfo.ILoginInfo;
}; };
export const rootReducer = combineReducers<IAppState>({ export const rootReducer = combineReducers<IAppState>({
...@@ -29,6 +31,7 @@ export const rootReducer = combineReducers<IAppState>({ ...@@ -29,6 +31,7 @@ export const rootReducer = combineReducers<IAppState>({
studentDataFields: studentDataFields.studentDataFieldsReducer, studentDataFields: studentDataFields.studentDataFieldsReducer,
epalclasses: epalclasses.epalclassesReducer, epalclasses: epalclasses.epalclassesReducer,
amkafills: amkafills.amkafillReducer, amkafills: amkafills.amkafillReducer,
loginInfo: loginInfo.loginInfoReducer,
}); });
export function deimmutify(state: IAppState): Object { export function deimmutify(state: IAppState): Object {
...@@ -40,5 +43,6 @@ export function deimmutify(state: IAppState): Object { ...@@ -40,5 +43,6 @@ export function deimmutify(state: IAppState): Object {
studentdataFields: studentDataFields.deimmutifyStudentDataFields(state.studentDataFields), studentdataFields: studentDataFields.deimmutifyStudentDataFields(state.studentDataFields),
epalclasses: epalclasses.deimmutifyEpalClasses(state.epalclasses), epalclasses: epalclasses.deimmutifyEpalClasses(state.epalclasses),
amkafills: amkafills.deimmutifyAmkaFills(state.amkafills), amkafills: amkafills.deimmutifyAmkaFills(state.amkafills),
loginInfo: loginInfo.deimmutifyLoginInfo(state.loginInfo),
}; };
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment