-
Notifications
You must be signed in to change notification settings - Fork 490
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Google Authentication. More work on ORCiD
- Loading branch information
1 parent
e637f43
commit e146e21
Showing
10 changed files
with
255 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
src/main/java/edu/harvard/iq/dataverse/authorization/providers/oauth2/OrcidApi.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...arvard/iq/dataverse/authorization/providers/oauth2/identityproviders/GoogleOAuth2Idp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package edu.harvard.iq.dataverse.authorization.providers.oauth2.identityproviders; | ||
|
||
import com.github.scribejava.apis.GoogleApi20; | ||
import com.github.scribejava.core.builder.api.BaseApi; | ||
import edu.harvard.iq.dataverse.authorization.AuthenticatedUserDisplayInfo; | ||
import edu.harvard.iq.dataverse.authorization.providers.oauth2.AbstractOAuth2Idp; | ||
import java.io.StringReader; | ||
import javax.json.Json; | ||
import javax.json.JsonObject; | ||
import javax.json.JsonReader; | ||
|
||
/** | ||
* | ||
* @author michael | ||
*/ | ||
public class GoogleOAuth2Idp extends AbstractOAuth2Idp { | ||
|
||
public GoogleOAuth2Idp() { | ||
id = "google"; | ||
title = "Google"; | ||
clientId = "372743369730-il7ohtgdemnvd2pqto8thluqgmpvu94b.apps.googleusercontent.com"; | ||
clientSecret = "WITHELD"; | ||
redirectUrl = "http://localhost:8080/oauth/callback.xhtml"; | ||
scope = "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email"; | ||
userEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo"; | ||
} | ||
|
||
@Override | ||
public BaseApi getApiInstance() { | ||
return GoogleApi20.instance(); | ||
} | ||
|
||
@Override | ||
protected ParsedUserResponse parseUserResponse(String responseBody) { | ||
try ( StringReader rdr = new StringReader(responseBody); | ||
JsonReader jrdr = Json.createReader(rdr) ) { | ||
JsonObject response = jrdr.readObject(); | ||
|
||
AuthenticatedUserDisplayInfo displayInfo = new AuthenticatedUserDisplayInfo( | ||
response.getString("given_name",""), | ||
response.getString("family_name",""), | ||
response.getString("email",""), | ||
"", | ||
"" | ||
); | ||
return new ParsedUserResponse(displayInfo, response.getString("id")); | ||
} | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...a/edu/harvard/iq/dataverse/authorization/providers/oauth2/identityproviders/OrcidApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package edu.harvard.iq.dataverse.authorization.providers.oauth2.identityproviders; | ||
|
||
import com.github.scribejava.core.builder.api.DefaultApi20; | ||
import com.github.scribejava.core.extractors.OAuth2AccessTokenExtractor; | ||
import com.github.scribejava.core.extractors.OAuth2AccessTokenJsonExtractor; | ||
import com.github.scribejava.core.extractors.TokenExtractor; | ||
import com.github.scribejava.core.model.OAuth2AccessToken; | ||
import com.github.scribejava.core.model.Response; | ||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Adaptor for ORCiD OAuth identity Provider. | ||
* @author michael | ||
*/ | ||
public class OrcidApi extends DefaultApi20 { | ||
|
||
/** | ||
* The instance holder pattern allows for lazy creation of the intance. | ||
*/ | ||
private static class InstanceHolder { | ||
private static final OrcidApi INSTANCE = new OrcidApi(); | ||
} | ||
|
||
public static OrcidApi instance() { | ||
return InstanceHolder.INSTANCE; | ||
} | ||
|
||
protected OrcidApi(){} | ||
|
||
@Override | ||
public String getAccessTokenEndpoint() { | ||
return "https://orcid.org/oauth/token"; | ||
} | ||
|
||
@Override | ||
protected String getAuthorizationBaseUrl() { | ||
return "https://orcid.org/oauth/authorize"; | ||
} | ||
|
||
@Override | ||
public TokenExtractor<OAuth2AccessToken> getAccessTokenExtractor() { | ||
return OAuth2AccessTokenJsonExtractor.instance(); | ||
} | ||
|
||
static class TE extends OAuth2AccessTokenJsonExtractor { | ||
|
||
@Override | ||
public OAuth2AccessToken extract(String response) { | ||
Logger.getAnonymousLogger().info("Response:"); | ||
Logger.getAnonymousLogger().info(response); | ||
Logger.getAnonymousLogger().info("/Response"); | ||
return super.extract(response); | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.