forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request IQSS#6192 from CIMMYT/6155-OAuth-2.0-Microsoft
IQSS#6155: OAuth 2.0 - Microsoft
- Loading branch information
Showing
9 changed files
with
92 additions
and
15 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions
8
doc/sphinx-guides/source/_static/installation/files/root/auth-providers/microsoft.json
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,8 @@ | ||
{ | ||
"id":"microsoft", | ||
"factoryAlias":"oauth2", | ||
"title":"Microsoft", | ||
"subtitle":"", | ||
"factoryData":"type: microsoft | userEndpoint: NONE | clientId: FIXME | clientSecret: FIXME", | ||
"enabled":true | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
.../java/edu/harvard/iq/dataverse/authorization/providers/oauth2/impl/MicrosoftOAuth2AP.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,60 @@ | ||
package edu.harvard.iq.dataverse.authorization.providers.oauth2.impl; | ||
|
||
import com.github.scribejava.apis.MicrosoftAzureActiveDirectory20Api; | ||
import com.github.scribejava.core.builder.api.DefaultApi20; | ||
import edu.harvard.iq.dataverse.authorization.providers.oauth2.AbstractOAuth2AuthenticationProvider; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.logging.Logger; | ||
import java.io.StringReader; | ||
import javax.json.Json; | ||
import javax.json.JsonObject; | ||
import javax.json.JsonReader; | ||
import edu.harvard.iq.dataverse.authorization.AuthenticatedUserDisplayInfo; | ||
|
||
/** | ||
* | ||
* @author | ||
*/ | ||
public class MicrosoftOAuth2AP extends AbstractOAuth2AuthenticationProvider{ | ||
|
||
private static final Logger logger = Logger.getLogger(MicrosoftOAuth2AP.class.getCanonicalName()); | ||
|
||
public MicrosoftOAuth2AP(String aClientId, String aClientSecret){ | ||
this.id = "microsoft"; | ||
this.title = "Microsoft"; | ||
this.clientId = aClientId; | ||
this.clientSecret = aClientSecret; | ||
this.scope = Arrays.asList("User.Read"); | ||
this.baseUserEndpoint = "https://graph.microsoft.com/v1.0/me"; | ||
} | ||
|
||
@Override | ||
public DefaultApi20 getApiInstance(){ | ||
return MicrosoftAzureActiveDirectory20Api.instance(); | ||
} | ||
|
||
@Override | ||
protected ParsedUserResponse parseUserResponse(final String responseBody) { | ||
try ( StringReader rdr = new StringReader(responseBody); | ||
JsonReader jrdr = Json.createReader(rdr) ) { | ||
JsonObject response = jrdr.readObject(); | ||
AuthenticatedUserDisplayInfo displayInfo = new AuthenticatedUserDisplayInfo( | ||
response.getString("givenName", ""), | ||
response.getString("surname", ""), | ||
response.getString("userPrincipalName", ""), | ||
"", ""); | ||
String persistentUserId = response.getString("id"); | ||
String username = response.getString("userPrincipalName"); | ||
return new ParsedUserResponse(displayInfo, persistentUserId, username, | ||
(displayInfo.getEmailAddress().length() > 0 ? Collections.singletonList(displayInfo.getEmailAddress()) : Collections.emptyList() ) | ||
); | ||
} | ||
} | ||
|
||
public boolean isDisplayIdentifier() | ||
{ | ||
return false; | ||
} | ||
} |
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