Adds OrcId login. (Issue #103)
This commit is contained in:
parent
f50b27128c
commit
23116d9a99
|
@ -82,6 +82,12 @@ public class Login {
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<B2AccessResponseToken>().payload(this.b2AccessTokenValidator.getAccessToken(b2AccessRequest)).status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<B2AccessResponseToken>().payload(this.b2AccessTokenValidator.getAccessToken(b2AccessRequest)).status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = {"/orcidRequestToken"}, produces = "application/json", consumes = "application/json")
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<ResponseItem<ORCIDResponseToken>> ORCIDRequestToken(@RequestBody ORCIDRequest orcidRequest) {
|
||||||
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ORCIDResponseToken>().payload(this.orcidTokenValidator.getAccessToken(orcidRequest)).status(ApiMessageCode.NO_MESSAGE));
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/me"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/me"}, consumes = "application/json", produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) throws NullEmailException {
|
ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) throws NullEmailException {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.logic.security.customproviders;
|
package eu.eudat.logic.security.customproviders.B2Access;
|
||||||
|
|
||||||
import eu.eudat.logic.security.validators.b2access.helpers.B2AccessResponseToken;
|
import eu.eudat.logic.security.validators.b2access.helpers.B2AccessResponseToken;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.logic.security.customproviders;
|
package eu.eudat.logic.security.customproviders.B2Access;
|
||||||
|
|
||||||
import com.google.api.client.repackaged.org.apache.commons.codec.binary.Base64;
|
import com.google.api.client.repackaged.org.apache.commons.codec.binary.Base64;
|
||||||
import eu.eudat.logic.security.validators.b2access.helpers.B2AccessResponseToken;
|
import eu.eudat.logic.security.validators.b2access.helpers.B2AccessResponseToken;
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.eudat.logic.security.customproviders;
|
package eu.eudat.logic.security.customproviders.B2Access;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ikalyvas on 2/22/2018.
|
* Created by ikalyvas on 2/22/2018.
|
|
@ -0,0 +1,9 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ORCID;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDResponseToken;
|
||||||
|
|
||||||
|
public interface ORCIDCustomProvider {
|
||||||
|
ORCIDUser getUser(String accessToken);
|
||||||
|
|
||||||
|
ORCIDResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret);
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ORCID;
|
||||||
|
|
||||||
|
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDResponseToken;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component("ORCIDCustomProvider")
|
||||||
|
public class ORCIDCustomProviderImpl implements ORCIDCustomProvider {
|
||||||
|
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ORCIDCustomProviderImpl(Environment environment) {
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ORCIDResponseToken getAccessToken(String code, String redirectUri, String clientId, String clientSecret) {
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("accept", "application/json");
|
||||||
|
|
||||||
|
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
|
||||||
|
map.add("client_id", this.environment.getProperty("orcid.login.client_id"));
|
||||||
|
map.add("client_secret", this.environment.getProperty("orcid.login.client_secret"));
|
||||||
|
map.add("grant_type", "authorization_code");
|
||||||
|
map.add("code", code);
|
||||||
|
map.add("redirect_uri", redirectUri);
|
||||||
|
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
|
||||||
|
|
||||||
|
Map<String, Object> values = restTemplate.postForObject(this.environment.getProperty("orcid.login.access_token_url"), request, Map.class);
|
||||||
|
ORCIDResponseToken orcidResponseToken = new ORCIDResponseToken();
|
||||||
|
orcidResponseToken.setOrcidId((String) values.get("orcid"));
|
||||||
|
orcidResponseToken.setName((String) values.get("name"));
|
||||||
|
orcidResponseToken.setAccessToken((String) values.get("access_token"));
|
||||||
|
|
||||||
|
return orcidResponseToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ORCIDUser getUser(String accessToken) {
|
||||||
|
RestTemplate restTemplate = new RestTemplate();
|
||||||
|
HttpHeaders headers = this.createBearerAuthHeaders(accessToken);
|
||||||
|
HttpEntity<String> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
|
//Map<String, Object> values = restTemplate.exchange(this.environment.getProperty("orcid.login.access_token_url"),);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HttpHeaders createBearerAuthHeaders(String accessToken) {
|
||||||
|
return new HttpHeaders() {{
|
||||||
|
String authHeader = "Bearer " + accessToken;
|
||||||
|
set("Authorization", authHeader);
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package eu.eudat.logic.security.customproviders.ORCID;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ORCIDUser {
|
||||||
|
private String orcidId;
|
||||||
|
private String name;
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
public String getOrcidId() {
|
||||||
|
return orcidId;
|
||||||
|
}
|
||||||
|
public void setOrcidId(String orcidId) {
|
||||||
|
this.orcidId = orcidId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ORCIDUser getOrcidUser(Object data) {
|
||||||
|
this.orcidId = (String) ((Map) data).get("orcidId");
|
||||||
|
this.name = (String) ((Map) data).get("name");
|
||||||
|
this.email = (String) ((Map) data).get("email");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
package eu.eudat.logic.security.validators.orcid;
|
||||||
|
|
||||||
|
import eu.eudat.exceptions.security.NonValidTokenException;
|
||||||
|
import eu.eudat.exceptions.security.NullEmailException;
|
||||||
|
import eu.eudat.logic.security.customproviders.ORCID.ORCIDCustomProvider;
|
||||||
|
import eu.eudat.logic.security.customproviders.ORCID.ORCIDUser;
|
||||||
|
import eu.eudat.logic.security.validators.TokenValidator;
|
||||||
|
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDRequest;
|
||||||
|
import eu.eudat.logic.security.validators.orcid.helpers.ORCIDResponseToken;
|
||||||
|
import eu.eudat.logic.services.ApiContext;
|
||||||
|
import eu.eudat.logic.services.operations.authentication.AuthenticationService;
|
||||||
|
import eu.eudat.models.data.login.LoginInfo;
|
||||||
|
import eu.eudat.models.data.loginprovider.LoginProviderUser;
|
||||||
|
import eu.eudat.models.data.security.Principal;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
|
||||||
|
@Component("orcidTokenValidator")
|
||||||
|
public class ORCIDTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
|
private ORCIDCustomProvider orcidCustomProvider;
|
||||||
|
private Environment environment;
|
||||||
|
private AuthenticationService nonVerifiedUserAuthenticationService;
|
||||||
|
private ApiContext apiContext;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ORCIDTokenValidator(Environment environment, AuthenticationService nonVerifiedUserAuthenticationService, ORCIDCustomProvider orcidCustomProvider, ApiContext apiContext) {
|
||||||
|
this.environment = environment;
|
||||||
|
this.nonVerifiedUserAuthenticationService = nonVerifiedUserAuthenticationService;
|
||||||
|
this.orcidCustomProvider = orcidCustomProvider;
|
||||||
|
this.apiContext = apiContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Principal validateToken(LoginInfo credentials) throws NonValidTokenException, IOException, GeneralSecurityException, NullEmailException {
|
||||||
|
ORCIDUser orcidUser = new ORCIDUser().getOrcidUser(credentials.getData());
|
||||||
|
LoginProviderUser user = new LoginProviderUser();
|
||||||
|
user.setId(orcidUser.getOrcidId());
|
||||||
|
user.setName(orcidUser.getName());
|
||||||
|
user.setProvider(credentials.getProvider());
|
||||||
|
user.setSecret(credentials.getTicket());
|
||||||
|
return this.nonVerifiedUserAuthenticationService.Touch(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ORCIDResponseToken getAccessToken(ORCIDRequest orcidRequest) {
|
||||||
|
return this.orcidCustomProvider.getAccessToken(orcidRequest.getCode(), this.environment.getProperty("orcid.login.redirect_uri")
|
||||||
|
, this.environment.getProperty("orcid.login.client_id")
|
||||||
|
, this.environment.getProperty("orcid.login.client_secret"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package eu.eudat.logic.security.validators.orcid.helpers;
|
||||||
|
|
||||||
|
public class ORCIDRequest {
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package eu.eudat.logic.security.validators.orcid.helpers;
|
||||||
|
|
||||||
|
public class ORCIDResponseToken {
|
||||||
|
private String orcidId;
|
||||||
|
private String name;
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
public String getOrcidId() {
|
||||||
|
return orcidId;
|
||||||
|
}
|
||||||
|
public void setOrcidId(String orcidId) {
|
||||||
|
this.orcidId = orcidId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccessToken() {
|
||||||
|
return accessToken;
|
||||||
|
}
|
||||||
|
public void setAccessToken(String accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,5 +4,6 @@ export enum AuthProvider {
|
||||||
Twitter = 3,
|
Twitter = 3,
|
||||||
LinkedIn = 4,
|
LinkedIn = 4,
|
||||||
//NativeLogin=5,
|
//NativeLogin=5,
|
||||||
B2Access = 6
|
B2Access = 6,
|
||||||
|
ORCID = 7
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
export class OrcidUser {
|
||||||
|
orcidId: string;
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
|
@ -2,23 +2,32 @@
|
||||||
<div class="login-logo"></div>
|
<div class="login-logo"></div>
|
||||||
<div class="card login-card">
|
<div class="card login-card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div class="social-btns d-flex">
|
<div class="social-btns d-flex flex-column">
|
||||||
<button *ngIf="hasGoogleOauth()" mat-icon-button id="googleSignInButton" class="login-social-button">
|
<div class="row">
|
||||||
<i class="fa fa-google"></i>
|
<button *ngIf="hasGoogleOauth()" mat-icon-button id="googleSignInButton" class="login-social-button">
|
||||||
</button>
|
<i class="fa fa-google"></i>
|
||||||
<button *ngIf="hasLinkedInOauth()" mat-icon-button class="login-social-button">
|
</button>
|
||||||
<i class="fa fa-linkedin" (click)="linkedInLogin()"></i>
|
<button *ngIf="hasLinkedInOauth()" mat-icon-button class="login-social-button">
|
||||||
</button>
|
<i class="fa fa-linkedin" (click)="linkedInLogin()"></i>
|
||||||
<button *ngIf="hasFacebookOauth()" mat-icon-button (click)="facebookLogin()" class="login-social-button">
|
</button>
|
||||||
<i class="fa fa-facebook-square"></i>
|
<button *ngIf="hasFacebookOauth()" mat-icon-button (click)="facebookLogin()" class="login-social-button">
|
||||||
</button>
|
<i class="fa fa-facebook-square"></i>
|
||||||
<button *ngIf="hasTwitterOauth()" mat-icon-button (click)="twitterLogin()" class="login-social-button">
|
</button>
|
||||||
<i class="fa fa-twitter"></i>
|
<button *ngIf="hasTwitterOauth()" mat-icon-button (click)="twitterLogin()" class="login-social-button">
|
||||||
</button>
|
<i class="fa fa-twitter"></i>
|
||||||
<button *ngIf="hasB2AccessOauth()" class="b2access-button" mat-icon-button (click)="b2AccessLogin()" class="login-social-button">
|
</button>
|
||||||
<span class="iconmedium"></span>
|
</div>
|
||||||
<span></span>
|
<div class="row justify-content-center">
|
||||||
</button>
|
<button *ngIf="hasB2AccessOauth()" class="b2access-button" mat-icon-button (click)="b2AccessLogin()" class="login-social-button">
|
||||||
|
<span class="iconmedium"></span>
|
||||||
|
<span></span>
|
||||||
|
</button>
|
||||||
|
<button *ngIf="hasOrcidOauth()" class="orcid-button" mat-icon-button (click)="orcidLogin()" class="login-social-button">
|
||||||
|
<span class="orcidIconMedium"></span>
|
||||||
|
<span></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<div class="card-footer">
|
||||||
|
|
|
@ -175,11 +175,25 @@ span.iconmedium {
|
||||||
margin-right: 2em;
|
margin-right: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span.orcidIconMedium {
|
||||||
|
background: url(img/ORCIDiD_medium.png) no-repeat;
|
||||||
|
float: right;
|
||||||
|
width: 100px;
|
||||||
|
height: 56px;
|
||||||
|
margin-left: 2em;
|
||||||
|
margin-right: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
.b2access-button {
|
.b2access-button {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.orcid-button {
|
||||||
|
margin-top: 10px;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
.login-logo {
|
.login-logo {
|
||||||
background: url(img/open-dmp.png) no-repeat;
|
background: url(img/open-dmp.png) no-repeat;
|
||||||
width: 370px;
|
width: 370px;
|
||||||
|
|
|
@ -51,7 +51,11 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
|
||||||
}
|
}
|
||||||
|
|
||||||
public b2AccessLogin() {
|
public b2AccessLogin() {
|
||||||
this.router.navigate(['/api/oauth/authorized/b2access']);
|
this.router.navigate(['/login/external/b2access']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public orcidLogin() {
|
||||||
|
this.router.navigate(['/login/external/orcid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasFacebookOauth(): boolean {
|
public hasFacebookOauth(): boolean {
|
||||||
|
@ -74,6 +78,10 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
|
||||||
return this.hasProvider(AuthProvider.B2Access);
|
return this.hasProvider(AuthProvider.B2Access);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public hasOrcidOauth(): boolean {
|
||||||
|
return this.hasProvider(AuthProvider.ORCID);
|
||||||
|
}
|
||||||
|
|
||||||
public initProviders() {
|
public initProviders() {
|
||||||
if (this.hasProvider(AuthProvider.Google)) { this.initializeGoogleOauth(); }
|
if (this.hasProvider(AuthProvider.Google)) { this.initializeGoogleOauth(); }
|
||||||
if (this.hasProvider(AuthProvider.Facebook)) { this.initializeFacebookOauth(); }
|
if (this.hasProvider(AuthProvider.Facebook)) { this.initializeFacebookOauth(); }
|
||||||
|
@ -93,6 +101,7 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn
|
||||||
case AuthProvider.LinkedIn: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.linkedInConfiguration);
|
case AuthProvider.LinkedIn: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.linkedInConfiguration);
|
||||||
case AuthProvider.Twitter: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.twitterConfiguration);
|
case AuthProvider.Twitter: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.twitterConfiguration);
|
||||||
case AuthProvider.B2Access: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.b2accessConfiguration);
|
case AuthProvider.B2Access: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.b2accessConfiguration);
|
||||||
|
case AuthProvider.ORCID: return this.hasAllRequiredFieldsConfigured(environment.loginProviders.orcidConfiguration);
|
||||||
default: throw new Error('Unsupported Provider Type');
|
default: throw new Error('Unsupported Provider Type');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import { LoginRoutingModule } from './login.routing';
|
||||||
import { TwitterLoginComponent } from './twitter-login/twitter-login.component';
|
import { TwitterLoginComponent } from './twitter-login/twitter-login.component';
|
||||||
import { LoginService } from './utilities/login.service';
|
import { LoginService } from './utilities/login.service';
|
||||||
import { B2AccessLoginComponent } from './b2access/b2access-login.component';
|
import { B2AccessLoginComponent } from './b2access/b2access-login.component';
|
||||||
|
import { OrcidLoginComponent } from './orcid-login/orcid-login.component';
|
||||||
|
import { EmailConfirmation } from './email-confirmation/email-confirmation.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -18,7 +20,9 @@ import { B2AccessLoginComponent } from './b2access/b2access-login.component';
|
||||||
LoginComponent,
|
LoginComponent,
|
||||||
LinkedInLoginComponent,
|
LinkedInLoginComponent,
|
||||||
TwitterLoginComponent,
|
TwitterLoginComponent,
|
||||||
B2AccessLoginComponent
|
B2AccessLoginComponent,
|
||||||
|
OrcidLoginComponent,
|
||||||
|
EmailConfirmation
|
||||||
],
|
],
|
||||||
providers: [LoginService]
|
providers: [LoginService]
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,15 +3,20 @@ import { RouterModule, Routes } from '@angular/router';
|
||||||
import { LinkedInLoginComponent } from './linkedin-login/linkedin-login.component';
|
import { LinkedInLoginComponent } from './linkedin-login/linkedin-login.component';
|
||||||
import { LoginComponent } from './login.component';
|
import { LoginComponent } from './login.component';
|
||||||
import { TwitterLoginComponent } from './twitter-login/twitter-login.component';
|
import { TwitterLoginComponent } from './twitter-login/twitter-login.component';
|
||||||
|
import { EmailConfirmation } from './email-confirmation/email-confirmation.component';
|
||||||
|
import { OrcidLoginComponent } from './orcid-login/orcid-login.component';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: '', component: LoginComponent },
|
{ path: '', component: LoginComponent },
|
||||||
{ path: 'linkedin', component: LinkedInLoginComponent },
|
{ path: 'linkedin', component: LinkedInLoginComponent },
|
||||||
{ path: 'twitter', component: TwitterLoginComponent }
|
{ path: 'twitter', component: TwitterLoginComponent },
|
||||||
|
{ path: 'external/orcid', component: OrcidLoginComponent },
|
||||||
|
{ path: 'confirmation/:token', component: EmailConfirmation },
|
||||||
|
{ path: 'confirmation', component: EmailConfirmation }
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [RouterModule.forChild(routes)],
|
imports: [RouterModule.forChild(routes)],
|
||||||
exports: [RouterModule]
|
exports: [RouterModule]
|
||||||
})
|
})
|
||||||
export class LoginRoutingModule { }
|
export class LoginRoutingModule { }
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { BaseComponent } from '../../../../core/common/base/base.component';
|
||||||
|
import { LoginService } from '../utilities/login.service';
|
||||||
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
|
import { takeUntil } from 'rxjs/operators';
|
||||||
|
import { environment } from '../../../../../environments/environment';
|
||||||
|
import { AuthService } from '../../../../core/services/auth/auth.service';
|
||||||
|
import { AuthProvider } from '../../../../core/common/enum/auth-provider';
|
||||||
|
import { HttpHeaders, HttpClient } from '@angular/common/http';
|
||||||
|
import { OrcidUser } from '../../../../core/model/orcid/orcidUser';
|
||||||
|
import { FormControl } from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-orcid-login',
|
||||||
|
templateUrl: './orcid-login.component.html',
|
||||||
|
styleUrls: ['./orcid-login.component.scss']
|
||||||
|
})
|
||||||
|
export class OrcidLoginComponent extends BaseComponent implements OnInit {
|
||||||
|
|
||||||
|
private returnUrl: string;
|
||||||
|
private orcidUser: OrcidUser
|
||||||
|
private accessToken: string;
|
||||||
|
private emailFormControl = new FormControl('');
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private authService: AuthService,
|
||||||
|
private loginService: LoginService,
|
||||||
|
private httpClient: HttpClient
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
this.orcidUser = new OrcidUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.route.queryParams
|
||||||
|
.pipe(takeUntil(this._destroyed))
|
||||||
|
.subscribe((params: Params) => {
|
||||||
|
const returnUrl = params['returnUrl'];
|
||||||
|
if (returnUrl) { this.returnUrl = returnUrl; }
|
||||||
|
if (!params['code']) { this.orcidAccessGetAuthCode(); } else { this.orcidLogin(params['code']); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public orcidAccessGetAuthCode() {
|
||||||
|
window.location.href = environment.loginProviders.orcidConfiguration.oauthUrl
|
||||||
|
+ '?client_id='
|
||||||
|
+ environment.loginProviders.orcidConfiguration.clientId
|
||||||
|
+ '&response_type=code&scope=/authenticate&redirect_uri='
|
||||||
|
+ environment.loginProviders.orcidConfiguration.redirectUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public orcidLogin(code: string) {
|
||||||
|
let headers = new HttpHeaders();
|
||||||
|
headers = headers.set('Content-Type', 'application/json');
|
||||||
|
headers = headers.set('Accept', 'application/json');
|
||||||
|
this.httpClient.post(environment.Server + 'auth/orcidRequestToken', { code: code }, { headers: headers })
|
||||||
|
.pipe(takeUntil(this._destroyed))
|
||||||
|
.subscribe((responseData: any) => {
|
||||||
|
this.orcidUser.orcidId = responseData.payload.orcidId
|
||||||
|
this.orcidUser.name = responseData.payload.name
|
||||||
|
this.accessToken = responseData.payload.accessToken;
|
||||||
|
this.authService.login({ ticket: this.accessToken, provider: AuthProvider.ORCID, data: this.orcidUser })
|
||||||
|
.pipe(takeUntil(this._destroyed))
|
||||||
|
.subscribe(
|
||||||
|
res => this.loginService.onLogInSuccess(res, this.returnUrl),
|
||||||
|
error => this.loginService.onLogInError(error)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public login() {
|
||||||
|
this.orcidUser.email = this.emailFormControl.value;
|
||||||
|
this.authService.login({ ticket: this.accessToken, provider: AuthProvider.ORCID, data: this.orcidUser })
|
||||||
|
.pipe(takeUntil(this._destroyed))
|
||||||
|
.subscribe(
|
||||||
|
res => this.loginService.onLogInSuccess(res, this.returnUrl),
|
||||||
|
error => this.loginService.onLogInError(error)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ export const environment = {
|
||||||
},
|
},
|
||||||
defaultCulture: 'en-US',
|
defaultCulture: 'en-US',
|
||||||
loginProviders: {
|
loginProviders: {
|
||||||
enabled: [1, 2, 3, 4, 5],
|
enabled: [1, 2, 3, 4, 5, 6],
|
||||||
facebookConfiguration: { clientId: '' },
|
facebookConfiguration: { clientId: '' },
|
||||||
googleConfiguration: { clientId: '' },
|
googleConfiguration: { clientId: '' },
|
||||||
linkedInConfiguration: {
|
linkedInConfiguration: {
|
||||||
|
@ -24,6 +24,11 @@ export const environment = {
|
||||||
clientId: '',
|
clientId: '',
|
||||||
oauthUrl: 'https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz',
|
oauthUrl: 'https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz',
|
||||||
redirectUri: 'http://opendmp.eu/api/oauth/authorized/b2access'
|
redirectUri: 'http://opendmp.eu/api/oauth/authorized/b2access'
|
||||||
|
},
|
||||||
|
orcidConfiguration: {
|
||||||
|
clientId: 'APP-766DI5LP8T75FC4R',
|
||||||
|
oauthUrl: 'https://sandbox.orcid.org/oauth/authorize',
|
||||||
|
redirectUri: 'http://opendmp.eu/api/oauth/authorized/orcid'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
logging: {
|
logging: {
|
||||||
|
|
|
@ -8,7 +8,7 @@ export const environment = {
|
||||||
},
|
},
|
||||||
defaultCulture: 'en-US',
|
defaultCulture: 'en-US',
|
||||||
loginProviders: {
|
loginProviders: {
|
||||||
enabled: [1, 2, 3, 4, 5],
|
enabled: [1, 2, 3, 4, 5, 6],
|
||||||
facebookConfiguration: { clientId: '' },
|
facebookConfiguration: { clientId: '' },
|
||||||
googleConfiguration: { clientId: '596924546661-83nhl986pnrpug5h624i5kptuao03dcd.apps.googleusercontent.com' },
|
googleConfiguration: { clientId: '596924546661-83nhl986pnrpug5h624i5kptuao03dcd.apps.googleusercontent.com' },
|
||||||
linkedInConfiguration: {
|
linkedInConfiguration: {
|
||||||
|
@ -24,6 +24,11 @@ export const environment = {
|
||||||
clientId: '',
|
clientId: '',
|
||||||
oauthUrl: 'https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz',
|
oauthUrl: 'https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz',
|
||||||
redirectUri: 'http://devel.opendmp.eu/api/oauth/authorized/b2access'
|
redirectUri: 'http://devel.opendmp.eu/api/oauth/authorized/b2access'
|
||||||
|
},
|
||||||
|
orcidConfiguration: {
|
||||||
|
clientId: '',
|
||||||
|
oauthUrl: 'https://sandbox.orcid.org/oauth/authorize',
|
||||||
|
redirectUri: 'http://opendmp.eu/api/oauth/authorized/orcid'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
logging: {
|
logging: {
|
||||||
|
|
|
@ -8,7 +8,7 @@ export const environment = {
|
||||||
},
|
},
|
||||||
defaultCulture: 'en-US',
|
defaultCulture: 'en-US',
|
||||||
loginProviders: {
|
loginProviders: {
|
||||||
enabled: [1, 2, 3, 4, 5, 6],
|
enabled: [1, 2, 3, 4, 5, 6, 7],
|
||||||
facebookConfiguration: { clientId: '' },
|
facebookConfiguration: { clientId: '' },
|
||||||
googleConfiguration: { clientId: '' },
|
googleConfiguration: { clientId: '' },
|
||||||
linkedInConfiguration: {
|
linkedInConfiguration: {
|
||||||
|
@ -24,6 +24,11 @@ export const environment = {
|
||||||
clientId: '',
|
clientId: '',
|
||||||
oauthUrl: 'https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz',
|
oauthUrl: 'https://b2access-integration.fz-juelich.de:443/oauth2-as/oauth2-authz',
|
||||||
redirectUri: 'http://opendmp.eu/api/oauth/authorized/b2access'
|
redirectUri: 'http://opendmp.eu/api/oauth/authorized/b2access'
|
||||||
|
},
|
||||||
|
orcidConfiguration: {
|
||||||
|
clientId: 'APP-766DI5LP8T75FC4R',
|
||||||
|
oauthUrl: 'https://orcid.org/oauth/authorize',
|
||||||
|
redirectUri: 'http://localhost:4200/login/external/orcid'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
logging: {
|
logging: {
|
||||||
|
|
Loading…
Reference in New Issue