Saranshmalik / react-native-zendesk

React native wrapper for Zendesk SDK
MIT License
29 stars 42 forks source link

JWT user identification #13

Open v-yer opened 3 years ago

v-yer commented 3 years ago

Hi, we need to set user identity with JWT token, but however everything is set in accordance with documentation, JWT identification does not work. The identity is set after RNZendeskChat.init() like this:

RNZendeskChat.init({
  key: __key__, //zendesk chat key
  appId: __appId__, //Zendesk Support app id
  url: __url__,
  clientId: __client__,
});

RNZendeskChat.setUserIdentity({
  token: __token__,
});

Starting chat with these options:

RNZendeskChat.startChat({
                name: __userName__,
                email: __userEmail__,
                chatOnly: true,
                botName: __botName__,
                department: '',
                color: __color__,
              })

In Zendesk Support Mobile SDK settings authentication metod is set to JWT and rest of settings are also done.

After enabling logs on Android app:

D/ZendeskIdentityManager: No previous identity set, storing identity
D/ZendeskIdentityStorage: Storing jwt identity

But still there is no call from Zendesk to our JWT endpoint and user authentication seems to be still anonymous. Is there anything else what should be set to make it work? Thanks for any help.

danielsram commented 3 years ago

help

Saranshmalik commented 3 years ago

Hi, So I looked upon the issue and seems like while I did do that for Support SDK since it was required there, I missed the same for the Chat SDK. I am looking to build a new version, and will fix this in that version but I can't commit on a date as of now, if you need it urgently, I would say to follow the steps here https://developer.zendesk.com/embeddables/docs/ios-unified-sdk/sdk_identify_users#chat-sdk-optional and here https://developer.zendesk.com/embeddables/docs/android-unified-sdk/sdk_identify_users#chat-sdk-optional Basically all you go to do is on set user identity function you need to call in an additional function to register it with the ChatProvider as well. Anyhow adding it to the next release work, on this PR #12 .

Saranshmalik commented 3 years ago

Okay so zendesk provides methods to use jwt authentication but expects the user to create payload and call the api on own and pass the fetched token to the chat client. Calling api from native module will make the library code complex and it is not ideal. So here is what I plan to implement, user will fetch token on own and pass the created token for zendesk on setUserIdentity, the library would store the token and pass it on to the chat client, the responsibility to generate token and get a new one on expiry will be on you. So before starting a chat you would need to ensure your last token is alive if not, fetch a new and call setUserIdentity again before starting the chat. Thoughts or better suggestions?

serbanbjd commented 3 years ago

currently setUserIdentity is not defined in the index.d.ts, I've seen a pr related to that, should that be merged?