2024-06-15 14:15:09 +02:00
|
|
|
package stirling.software.SPDF.model.provider;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
|
2025-01-22 15:14:06 +00:00
|
|
|
import lombok.NoArgsConstructor;
|
2024-06-15 14:15:09 +02:00
|
|
|
|
2025-01-22 15:14:06 +00:00
|
|
|
// @Setter
|
|
|
|
@NoArgsConstructor
|
2024-06-15 14:15:09 +02:00
|
|
|
public class GoogleProvider extends Provider {
|
|
|
|
|
2025-01-22 15:14:06 +00:00
|
|
|
private static final String NAME = "google";
|
|
|
|
private static final String CLIENT_NAME = "Google";
|
|
|
|
private static final String AUTHORIZATION_URI = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
|
|
private static final String TOKEN_URI = "https://www.googleapis.com/oauth2/v4/token";
|
|
|
|
private static final String USER_INFO_URI =
|
2024-06-15 14:15:09 +02:00
|
|
|
"https://www.googleapis.com/oauth2/v3/userinfo?alt=json";
|
2025-01-22 15:14:06 +00:00
|
|
|
|
2024-12-24 09:52:53 +00:00
|
|
|
private String clientId;
|
|
|
|
private String clientSecret;
|
|
|
|
private Collection<String> scopes = new ArrayList<>();
|
|
|
|
private String useAsUsername = "email";
|
2024-06-15 14:15:09 +02:00
|
|
|
|
2025-01-22 15:14:06 +00:00
|
|
|
public GoogleProvider(
|
|
|
|
String clientId, String clientSecret, Collection<String> scopes, String useAsUsername) {
|
|
|
|
super(null, NAME, CLIENT_NAME, clientId, clientSecret, scopes, useAsUsername);
|
|
|
|
this.clientId = clientId;
|
|
|
|
this.clientSecret = clientSecret;
|
|
|
|
this.scopes = scopes;
|
|
|
|
this.useAsUsername = useAsUsername;
|
2024-08-16 12:57:37 +02:00
|
|
|
}
|
|
|
|
|
2025-01-22 15:14:06 +00:00
|
|
|
public String getAuthorizationUri() {
|
|
|
|
return AUTHORIZATION_URI;
|
2024-06-15 14:15:09 +02:00
|
|
|
}
|
|
|
|
|
2025-01-22 15:14:06 +00:00
|
|
|
public String getTokenUri() {
|
|
|
|
return TOKEN_URI;
|
2024-06-15 14:15:09 +02:00
|
|
|
}
|
|
|
|
|
2025-01-22 15:14:06 +00:00
|
|
|
public String getUserinfoUri() {
|
|
|
|
return USER_INFO_URI;
|
2024-06-15 14:15:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Collection<String> getScopes() {
|
|
|
|
if (scopes == null || scopes.isEmpty()) {
|
|
|
|
scopes = new ArrayList<>();
|
|
|
|
scopes.add("https://www.googleapis.com/auth/userinfo.email");
|
|
|
|
scopes.add("https://www.googleapis.com/auth/userinfo.profile");
|
|
|
|
}
|
|
|
|
return scopes;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "Google [clientId="
|
|
|
|
+ clientId
|
|
|
|
+ ", clientSecret="
|
|
|
|
+ (clientSecret != null && !clientSecret.isEmpty() ? "MASKED" : "NULL")
|
|
|
|
+ ", scopes="
|
|
|
|
+ scopes
|
|
|
|
+ ", useAsUsername="
|
|
|
|
+ useAsUsername
|
|
|
|
+ "]";
|
|
|
|
}
|
|
|
|
}
|