Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#6155: OAuth 2.0 - Microsoft #6192

Merged
merged 22 commits into from
Oct 29, 2019
Merged

Conversation

alejandratenorio
Copy link
Contributor

@alejandratenorio alejandratenorio commented Sep 19, 2019

New Contributors

Welcome! New contributors should at least glance at CONTRIBUTING.md, especially the section on pull requests where we encourage you to reach out to other developers before you start coding. Also, please note that we measure code coverage and prefer you write unit tests. Pull requests can still be reviewed without tests or completion of the checklist outlined below. Thanks!

Related Issues

Pull Request Checklist

@dataversebot
Copy link

Can one of the admins verify this patch?

@coveralls
Copy link

coveralls commented Sep 19, 2019

Coverage Status

Coverage decreased (-0.004%) to 19.451% when pulling ab8714e on CIMMYT:6155-OAuth-2.0-Microsoft into 96efe2f on IQSS:develop.

@poikilotherm
Copy link
Contributor

Since the merge of gdcc/dataverse-kubernetes#87, I am working on #5991 and it's recent PR about updating ScribeJava. It might be a good idea to have that merged first, so it doesn't have to be me testing the Microsoft OAuth2... 😉

Copy link
Member

@pdurbin pdurbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! The main thing this pull request needs is documentation in doc/sphinx-guides/source/installation/oauth2.rst

@alejandratenorio do you want to work on this?

Also, I left a comment about JSON vs. XML.

@@ -116,6 +116,10 @@ public OAuth2UserRecord getUserRecord(String code, String state, String redirect
final OAuthRequest request = new OAuthRequest(Verb.GET, userEndpoint, service);
request.addHeader("Authorization", "Bearer " + accessToken.getAccessToken());
request.setCharset("UTF-8");

// Microsoft
request.addHeader("Accept", "application/json");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly concerned about this because doesn't ORCID use XML instead of JSON?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

13:48
Hi!

We use this line because Microsoft identity platform needs this header when send
an authentication request. If this header is out, we receive an error.

image

We work in a fix for the ORCID XML problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gerafp perfect. Thanks! Please let us know when that fix is in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Gerafp - I'll move this PR back to Community Dev.

Copy link
Contributor

@Gerafp Gerafp Sep 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi.

We add a instruction for manage the authentication request when use Microsoft.

The branch has updated with our fix.

@djbrooke djbrooke self-assigned this Sep 19, 2019
@djbrooke
Copy link
Contributor

Hi @Gerafp and @alejandratenorio, can one of you please give me permission to push to this branch? I have some documentation edits ready to push. Thanks!

@alejandratenorio
Copy link
Contributor Author

Hi @Gerafp and @alejandratenorio, can one of you please give me permission to push to this branch? I have some documentation edits ready to push. Thanks!

@djbrooke, sure, it's done.

Copy link
Contributor

@poikilotherm poikilotherm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be aware that in current releases of ScribeJava an upstream API client is available for this Microsoft endpoint. IMHO it would be a pity to refactor in #5997 and not use the advantages of an updated lib.

@djbrooke
Copy link
Contributor

Thanks @Gerafp and @alejandratenorio for giving me push access! Please take a look at the docs I added and feel free to expand those sections if necessary. Also note that I did not add any info about the json template at line 55 in oauth.rst, as it seems that still needs to be finalized. Thanks again for this contribution!

@pdurbin
Copy link
Member

pdurbin commented Sep 20, 2019

Please be aware that in current releases of ScribeJava an upstream API client is available for this Microsoft endpoint.

I'm a little confused.

Currently Dataverse uses ScribeJava 3.1.0. According to https://github.com/scribejava/scribejava/tree/scribejava-3.1.0#supports-all-major-10a-and-20-oauth-apis-out-of-the-box the following Microsoft API is supported in 3.1.0:

If we upgrade to ScribeJava 6.8.1 (the latest), https://github.com/scribejava/scribejava/tree/scribejava-6.8.1#supports-all-major-10a-and-20-oauth-apis-out-of-the-box indicates that a total of three Microsoft APIs are supported:

Which of these three Microsoft APIs will Dataverse support when this pull request is merged? All of them? One of them?

@alejandratenorio
Copy link
Contributor Author

Thanks @Gerafp and @alejandratenorio for giving me push access! Please take a look at the docs I added and feel free to expand those sections if necessary. Also note that I did not add any info about the json template at line 55 in oauth.rst, as it seems that still needs to be finalized. Thanks again for this contribution!

@djbrooke, I added info about microsoft.json file.

Gerafp added 2 commits September 20, 2019 15:27
…dataverse into 6155-OAuth-2.0-Microsoft

Add fix for ORCID XML problem when a user is autenticated with Microsoft
Copy link
Member

@pdurbin pdurbin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that 9ef52c5 is in I believe the code is ready for QA so I'm approving this. The docs seem to be in pretty good shape too.

@djbrooke djbrooke self-assigned this Oct 25, 2019
@djbrooke
Copy link
Contributor

I have one or two more things to check here. Hoping to move over before standup. :)

@djbrooke
Copy link
Contributor

Thanks all, sorry for the delay. I made one last change to generalize an error message in ab8714e. I'm also fine with the buttons as they are. I'm going to move this over to QA now. I'll take a look at the docs in parallel.

@kcondon, I tested this successfully with an outlook.com account I created and I also tested this with my Harvard institutional account and the flow worked as I expected, in line with our other Oauth login options. I know that we talked about this a little bit this morning, but if you want to discuss in more detail let me know.

@djbrooke djbrooke removed their assignment Oct 25, 2019
@kcondon
Copy link
Contributor

kcondon commented Oct 25, 2019

Hi @Gerafp , I'm testing this pr and running into a bit of an issue. You've tested both public (microsoft live?) and institutional azure ad/oauth accounts, correct? When you did so, how did you get your client id and secret to configure Dataverse? My understanding from the Azure AD link provided in the docs is one needs to register the app (dataverse), with the Azure AD tenant (directory authenticator/IdP), and that is what gives you the id and secret. If that is the case, I understand about the institutional AD registration and am pursuing that with my local university. However, how does that work with a public service like Live? I'm reading about the /tenant versus the /common userEndpoint but not sure how/where to register to get the right credentials. Thanks for any advice. Kevin P.S. Is this implementation multi-tenant by default? I was looking at this: https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-convert-app-to-be-multi-tenant

@Gerafp
Copy link
Contributor

Gerafp commented Oct 25, 2019

Hi @Gerafp , I'm testing this pr and running into a bit of an issue. You've tested both public (microsoft live?) and institutional azure ad/oauth accounts, correct? When you did so, how did you get your client id and secret to configure Dataverse? My understanding from the Azure AD link provided in the docs is one needs to register the app (dataverse), with the Azure AD tenant (directory authenticator/IdP), and that is what gives you the id and secret. If that is the case, I understand about the institutional AD registration and am pursuing that with my local university. However, how does that work with a public service like Live? I'm reading about the /tenant versus the /common userEndpoint but not sure how/where to register to get the right credentials. Thanks for any advice. Kevin P.S. Is this implementation multi-tenant by default? I was looking at this: https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-convert-app-to-be-multi-tenant

Hi @kcondon.

You can registry your app in this link

Documentation

When you registry you app, You obtain the client_id and secret for testing Dataverse.

@djbrooke
Copy link
Contributor

Thanks @Gerafp we'll take another look at this on Monday!

@djbrooke djbrooke self-assigned this Oct 25, 2019
@kcondon
Copy link
Contributor

kcondon commented Oct 26, 2019

@Gerafp @djbrooke

So, I followed the above link and it takes me to the azure portal. My account does not have permission to register an application. This is what I had encountered before.

I had looked at the developer quick start guide earlier and that was helpful in better understanding how the accounts worked and how multi tenant (common) and single tenant (tenantid) endpoints worked to support a variety of microsoft identities.

What I think I learned is this:

  1. To configure and use Dataverse with Microsoft Azure AD, you need an Azure subscription that allows creating and managing an Azure AD.
  2. You need an Azure AD tenant, either create one or use an existing one. A tenant represents an organization or institution.
  3. You need an Azure account that has permission to register an application for at least one tenant.
  4. Once you register Dataverse, you will get a client id and secret. Update your microsoft.json file with this information.
  5. All tenants support both the tenantId and common endpoints, so I think this means you can choose the scope of authentication, whether all Microsoft accounts, regardless of AD (multitenant), or microsoft accounts managed by a single organization (single tenant), by specifying the userEndpoint in microsoft.json, either https://login.microsoftonline.com/{tenantId} or https://login.microsoftonline.com/common. I don't know if login.microsoftonline.com is the literal value or whether it is the tenant name: harvard.microsoftonline.com
  6. Now that the microsoft.json file is completed with credentials and endpoint, use the Dataverse api to add Microsoft Azure AD Oauth as an authentication provider.

Would you confirm these steps are correct? Also, please send the microsoft.json file(s) you used for institutional and public account testing, client id and secret removed.

If the above directions are correct, I think we should make the instructions more like these.

@djbrooke
Copy link
Contributor

I've reached out to our contacts at Harvard to try and set up some test institutional creds.

@alejandratenorio
Copy link
Contributor Author

@Gerafp @djbrooke

So, I followed the above link and it takes me to the azure portal. My account does not have permission to register an application. This is what I had encountered before.

I had looked at the developer quick start guide earlier and that was helpful in better understanding how the accounts worked and how multi tenant (common) and single tenant (tenantid) endpoints worked to support a variety of microsoft identities.

What I think I learned is this:

  1. To configure and use Dataverse with Microsoft Azure AD, you need an Azure subscription that allows creating and managing an Azure AD.
  2. You need an Azure AD tenant, either create one or use an existing one. A tenant represents an organization or institution.
  3. You need an Azure account that has permission to register an application for at least one tenant.
  4. Once you register Dataverse, you will get a client id and secret. Update your microsoft.json file with this information.
  5. All tenants support both the tenantId and common endpoints, so I think this means you can choose the scope of authentication, whether all Microsoft accounts, regardless of AD (multitenant), or microsoft accounts managed by a single organization (single tenant), by specifying the userEndpoint in microsoft.json, either https://login.microsoftonline.com/{tenantId} or https://login.microsoftonline.com/common. I don't know if login.microsoftonline.com is the literal value or whether it is the tenant name: harvard.microsoftonline.com
  6. Now that the microsoft.json file is completed with credentials and endpoint, use the Dataverse api to add Microsoft Azure AD Oauth as an authentication provider.

Would you confirm these steps are correct? Also, please send the microsoft.json file(s) you used for institutional and public account testing, client id and secret removed.

If the above directions are correct, I think we should make the instructions more like these.

Hi @kcondon,

What kind of account did you use? I used my personal account (live.com.mx) and my cgiar account, in both I have permission to register an application.

@kcondon
Copy link
Contributor

kcondon commented Oct 28, 2019

@alejandratenorio When I clicked on the azure portal I was automatically logged in and under switch directory I saw Harvard University as a tenant. Harvard has a subscription, as I understand it, because they provide access to Microsoft cloud applications and we use outlook/web for email. My guess is I have a regular user account as defined by our organization. That is why I was emphasizing the permissions part. I do have a support request in to our IT group for more information. Also, at @pdurbin suggestion, I created a new microsoft account, accessed the portal and had even less permission -no tenants, no ability to click on switch directories.

@Gerafp
Copy link
Contributor

Gerafp commented Oct 28, 2019

@alejandratenorio When I clicked on the azure portal I was automatically logged in and under switch directory I saw Harvard University as a tenant. Harvard has a subscription, as I understand it, because they provide access to Microsoft cloud applications and we use outlook/web for email. My guess is I have a regular user account as defined by our organization. That is why I was emphasizing the permissions part. I do have a support request in to our IT group for more information. Also, at @pdurbin suggestion, I created a new microsoft account, accessed the portal and had even less permission -no tenants, no ability to click on switch directories.

Hi!

I dont know the reason becausse this happen, Can you give me access to a institutional account for check this situation?.

Personally, I have a institutional account with domain alumno.buap.mx and can register a new application in Azure AD.

image

image

@djbrooke
Copy link
Contributor

djbrooke commented Oct 28, 2019

Thanks @Gerafp. We unfortunately do not have the ability to edit any of this from our side, as the institutional account here is centrally managed. We're waiting to hear back from support and I'll let you know as soon as I have more information.

I also reached out to our local ops group to see if they have any ideas.

@kcondon
Copy link
Contributor

kcondon commented Oct 29, 2019

@alejandratenorio @Gerafp OK, I was able to get the live account to work, thanks for the link. I was also able to get the account I create from Friday working. Not sure why it did not work when I tried it. I can also authenticate my institutional account when I specify the user endpoint: https://login.microsoftonline.com/common but I am unable to register an app with that account -presumably due to a local IT policy. So, this can be merged. Apologies for the confusion. Kevin

@kcondon kcondon merged commit 4470369 into IQSS:develop Oct 29, 2019
@djbrooke djbrooke added this to the 4.18 milestone Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OAuth 2.0 - Microsoft
10 participants