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
|
||||
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);
|
||||
AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(oAuthToken, verifier);
|
||||
OAuthToken finalOauthToken = this.twitterServiceProvider.getOAuthOperations().exchangeForAccessToken(authorizedRequestToken, null);
|
||||
|
@ -48,11 +49,18 @@ public class TwitterTokenValidator implements TokenValidator {
|
|||
LoginProviderUser user = new LoginProviderUser();
|
||||
|
||||
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)
|
||||
throw new UnauthorisedException("Cannot login user.Twitter account did not provide email");
|
||||
user.setEmail((String) values.get("email"));
|
||||
if (values.get("email") == null) {
|
||||
// throw new UnauthorisedException("Cannot login user.Twitter account did not provide 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.setIsVerified(true); //TODO
|
||||
user.setId("" + profile.getId());
|
||||
user.setName(profile.getName());
|
||||
user.setProvider(TokenValidatorFactoryImpl.LoginProvider.TWITTER);
|
||||
|
|
|
@ -9,6 +9,8 @@ import { BaseComponent } from '@common/base/base.component';
|
|||
import { environment } from 'environments/environment';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
|
||||
import { FormControl } from '@angular/forms';
|
||||
import { stringify } from 'querystring';
|
||||
|
||||
@Component({
|
||||
selector: 'app-twitter-login',
|
||||
|
@ -17,6 +19,7 @@ import { ConfigurationService } from '@app/core/services/configuration/configura
|
|||
export class TwitterLoginComponent extends BaseComponent implements OnInit {
|
||||
|
||||
private returnUrl: string;
|
||||
private emailFormControl = new FormControl('');
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
|
@ -50,7 +53,10 @@ export class TwitterLoginComponent extends BaseComponent implements OnInit {
|
|||
}
|
||||
|
||||
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))
|
||||
.subscribe(
|
||||
res => this.loginService.onLogInSuccess(res, this.returnUrl),
|
||||
|
|
Loading…
Reference in New Issue