Java, Evernote : Revoke access for app on Evernote

2019-08-10 17:02发布

I am working on a Java project which has Evernote services integrated into it through an app created on Evernote. Currently, everything is working fine except for access-revocation.

When an user who has already authorized the app, at some point decides not to give this app any access, I would like to also de-authorize the app from the users evernote account.

For this, I am searching for some sample, but came empty handed. One link I found was this, where it was required to call that method with UserStore. I have the access-token, but unfortunately I am only working with NoteStoreClient, rather than UserStore.

Here is the revocation code I have so far.

 Person person = this.personService.getCurrentlyAuthenticatedUser();

        if (!(person == null)) {
            if (person.isEvernoteConsumed()) {
                try {
                    this.evernoteDAO.deleteEvernoteForUser(person.getId());

                    Evernote evernote = getUsersEvernote(person.getId());
                    EvernoteAuth evernoteAuth = new EvernoteAuth(EVERNOTE_SERVICE, evernote.getAccessToken());
                    NoteStoreClient noteStoreClient = new ClientFactory(evernoteAuth).createNoteStoreClient();

                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }

Nothing fancy in that code, I know. If anyone has any idea of revocation from Evernote, kindly let me know. Thank you.

1条回答
仙女界的扛把子
2楼-- · 2019-08-10 17:33

You're on the right track, that UserStore method will let you revoke your OAuth session. Like you said, you have to use the userstore client instead, you should be able to create it the same way as you did the notestore client:

UserStoreClient userStoreClient =
  new ClientFactory(evernoteAuth).createUserStoreClient();
userStoreClient.revokeLongSession(evernoteAuth);
查看更多
登录 后发表回答