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

ZCS-2691 Create DataSource implementation for LinkedIn contacts via oAuth #44

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

chinmay15
Copy link
Contributor

@chinmay15 chinmay15 commented Jul 24, 2018

Problem/Task: create datasource implementation for Linkedin contacts sync using oAuth2

Fix:

  1. Authorize and authenticate using oAuth2 rest api provided by Linkedin
  2. Folder created is with name as <username>-contact-linkedin, as profile call for linkedin needs "r_fullprofile" permission and this permission in given by linkedin on request. Request with linkedin support is raised.

Testing done:

  1. Contact folder and datasource is created in user account.
  2. Tested functionality manually.
zmprov gds cp1
# name [email protected]
# type oauth2contact
objectClass: zimbraDataSource
zimbraCreateTimestamp: 20180724133602.672Z
zimbraDataSourceConnectionType: cleartext
zimbraDataSourceEnabled: TRUE
zimbraDataSourceFolderId: 60020
zimbraDataSourceHost: www.linkedin.com
zimbraDataSourceId: 54e84c2e-50e5-405f-aa60-9c008d41aac0
zimbraDataSourceImportClassName: com.zimbra.oauth.handlers.impl.LinkedinContactsImport
zimbraDataSourceImportOnly: FALSE
zimbraDataSourceName: [email protected]
zimbraDataSourceOAuthRefreshToken: VALUE-BLOCKED
zimbraDataSourcePollingInterval: 1d
zimbraDataSourceType: oauth2contact

Testing needs to be done by QA:

  1. go to https://www.linkedin.com/developer/apps
  2. create app from - my apps -> create app
  3. select default app permissions "r_basicprofile" and "r_emailaddress"
  4. add "https://<your_host_name>/service/extension/oauth2/authenticate/linkedin" OAuth 2.0 authorized redirect url
  5. set zimbraOAuthConsumerRedirectUri: https://cpathak.zdev.local/service/extension/oauth2/authenticate/linkedin:linkedin
  6. set zimbraOAuthConsumerCredentials: <app_client_id>:<app_client_secret>:linkedin
  7. Make sure, Authorization and Authentication is done using oAuth2
  8. Make sure, contacts folder and datasource is created as mentioned above

Linked PR:
Zimbra/zm-mailbox#696

import com.zimbra.oauth.utilities.LdapConfiguration;

/**
* The FacebookContactsImport class.<br>
Copy link
Collaborator

@desouzas desouzas Jul 24, 2018

Choose a reason for hiding this comment

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

LinkedinContactsImport

Also missing this docblock header on the handler class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

AUTHENTICATE_URI("https://www.linkedin.com/oauth/v2/accessToken"),
ACCESS_TOKEN("access_token"),
EXPIRES_IN("expires_in")
;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Put this on the line before for consistency with the project. Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

ID("id"),
FIRST_NAME("firstName"),
LAST_NAME("lastName")
;
Copy link
Collaborator

Choose a reason for hiding this comment

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

^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

ERROR_DESCRIPTION("error_description"),
DEFAULT_ERROR("default_error"),
SERVICE_ERROR_CODE("serviceErrorCode"),
ERROR_MESSAGE("message"),
Copy link
Collaborator

@desouzas desouzas Jul 24, 2018

Choose a reason for hiding this comment

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

Is this and error_description a key? Move each of the response keys to the general LinkedInOAuth2Constants Keep your error codes in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved

// get zimbra mailbox
final ZMailbox mailbox = getZimbraMailbox(oauthInfo.getZmAuthToken());

// store refreshToken
Copy link
Collaborator

Choose a reason for hiding this comment

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

// store accessToken

May not be unreasonable to note that linkedin tokens are short-lived only. But that could be left for the import implementation where a small change may be necessary in syncDatasource to not set a polling time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// store accessToken

@@ -60,6 +60,21 @@
* @copyright Copyright © 2018
*/
public abstract class OAuth2Handler {
// for relay encoding
public enum RelayEnum {
RELAY("relay"),
Copy link
Collaborator

@desouzas desouzas Jul 24, 2018

Choose a reason for hiding this comment

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

These constants already exist in the project.
https://github.com/Zimbra/zm-oauth-social/blob/develop/src/java/com/zimbra/oauth/utilities/OAuth2HttpConstants.java#L38

Also "relay" isn't used anymore since the tickets with the ds type updates - it's now "state" into the authorize call, and whatever the social service uses out to the social service (typically "state" - but configurable for each service), and same thing on return into authenticate (whatever the service uses).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this enum is not used anywhere, so removed. I added it while i was testing JweUtil to pass the relay values but i removed that part of code.

}

@Override
protected String getPrimaryEmail(JsonNode credentials, Account account) throws ServiceException {
Copy link
Collaborator

@desouzas desouzas Jul 24, 2018

Choose a reason for hiding this comment

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

Format all of this method's source (lines appear too long).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

formatted code

@desouzas
Copy link
Collaborator

desouzas commented Aug 9, 2018

Don't merge this since we're putting linked aside for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants