Allow twitter oauth to login without email (ask when logging in)
This commit is contained in:
parent
194ae2ccf0
commit
4d59821b6c
|
@ -39,7 +39,8 @@ public class TwitterTokenValidator implements TokenValidator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Principal validateToken(LoginInfo credentials) throws NonValidTokenException, IOException, GeneralSecurityException, NullEmailException {
|
public Principal validateToken(LoginInfo credentials) throws NonValidTokenException, IOException, GeneralSecurityException, NullEmailException {
|
||||||
String verifier = (String) credentials.getData();
|
String verifier = (String) ((Map)credentials.getData()).get("verifier");
|
||||||
|
String email = (String) ((Map) credentials.getData()).get("email");
|
||||||
OAuthToken oAuthToken = new OAuthToken(credentials.getTicket(), verifier);
|
OAuthToken oAuthToken = new OAuthToken(credentials.getTicket(), verifier);
|
||||||
AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(oAuthToken, verifier);
|
AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(oAuthToken, verifier);
|
||||||
OAuthToken finalOauthToken = this.twitterServiceProvider.getOAuthOperations().exchangeForAccessToken(authorizedRequestToken, null);
|
OAuthToken finalOauthToken = this.twitterServiceProvider.getOAuthOperations().exchangeForAccessToken(authorizedRequestToken, null);
|
||||||
|
@ -48,11 +49,18 @@ public class TwitterTokenValidator implements TokenValidator {
|
||||||
LoginProviderUser user = new LoginProviderUser();
|
LoginProviderUser user = new LoginProviderUser();
|
||||||
|
|
||||||
Map values = twitterTemplate.getRestTemplate().getForObject("https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true", Map.class);
|
Map values = twitterTemplate.getRestTemplate().getForObject("https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true", Map.class);
|
||||||
if (values.get("email") == null)
|
if (values.get("email") == null) {
|
||||||
throw new UnauthorisedException("Cannot login user.Twitter account did not provide email");
|
// throw new UnauthorisedException("Cannot login user.Twitter account did not provide email");
|
||||||
user.setEmail((String) values.get("email"));
|
user.setIsVerified(false); //TODO
|
||||||
|
if (email != null && !email.isEmpty()) {
|
||||||
|
user.setEmail(email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
user.setEmail((String) values.get("email"));
|
||||||
|
user.setIsVerified(true); //TODO
|
||||||
|
}
|
||||||
user.setAvatarUrl(profile.getProfileImageUrl());
|
user.setAvatarUrl(profile.getProfileImageUrl());
|
||||||
user.setIsVerified(true); //TODO
|
|
||||||
user.setId("" + profile.getId());
|
user.setId("" + profile.getId());
|
||||||
user.setName(profile.getName());
|
user.setName(profile.getName());
|
||||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.TWITTER);
|
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.TWITTER);
|
||||||
|
|
|
@ -9,6 +9,8 @@ import { BaseComponent } from '@common/base/base.component';
|
||||||
import { environment } from 'environments/environment';
|
import { environment } from 'environments/environment';
|
||||||
import { takeUntil } from 'rxjs/operators';
|
import { takeUntil } from 'rxjs/operators';
|
||||||
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
|
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
|
||||||
|
import { FormControl } from '@angular/forms';
|
||||||
|
import { stringify } from 'querystring';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-twitter-login',
|
selector: 'app-twitter-login',
|
||||||
|
@ -17,6 +19,7 @@ import { ConfigurationService } from '@app/core/services/configuration/configura
|
||||||
export class TwitterLoginComponent extends BaseComponent implements OnInit {
|
export class TwitterLoginComponent extends BaseComponent implements OnInit {
|
||||||
|
|
||||||
private returnUrl: string;
|
private returnUrl: string;
|
||||||
|
private emailFormControl = new FormControl('');
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
|
@ -50,7 +53,10 @@ export class TwitterLoginComponent extends BaseComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
public twitterLogin(token: string, verifier: string) {
|
public twitterLogin(token: string, verifier: string) {
|
||||||
this.authService.login({ ticket: token, provider: AuthProvider.Twitter, data: verifier })
|
const data = {
|
||||||
|
email: this.emailFormControl.value, verifier: verifier
|
||||||
|
};
|
||||||
|
this.authService.login({ ticket: token, provider: AuthProvider.Twitter, data: data })
|
||||||
.pipe(takeUntil(this._destroyed))
|
.pipe(takeUntil(this._destroyed))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
res => this.loginService.onLogInSuccess(res, this.returnUrl),
|
res => this.loginService.onLogInSuccess(res, this.returnUrl),
|
||||||
|
|
Loading…
Reference in New Issue