Using OAuth authentication with your application Follow

Comments

9 comments

  • Avatar
    Seven Zhang

    Thank you very much.

  • Avatar
    Aditya Verma

    My application supports only Oauth 1.0, will I be able to use Oauth authentication with Zendesk?

    Regards,
    Aditya

  • Avatar
    Bryan Flynn

     Hi Aditya -- The OAuth 2.0 flows mentioned above are the ones Zendesk supports.

    Along with this article, here's some more background info on the supported OAuth 2.0 options: https://support.zendesk.com/hc/en-us/articles/203663426-Having-the-talk-Am-I-ready-for-a-more-advanced-authentication-option

    Hope this helps!

  • Avatar
    Jens Holmer

    Hi There, 

    First of all its a pretty good guide. Making OAuth flow work with the example from Implicit Grant Flow, was very easy :)

    However id like to be using the Authorization code grant flow instead. So i followed your steps and I am getting Authorization Code from query parameter code just fine. But when i run the provided Curl snippet or xhr to the token endpoint I get error invalid_client with  error description "The client identifier provided is invalid, the client failed to authenticate, the client did not include its credentials, provided multiple client credentials, or used unsupported credentials type".

    I've been checking my provided credentials over and over, since that would be the obvious place for my issue. I've Also tried to regenerate the client_secret and then granting new code to try with but i am having no luck.

    Just in case my body is: 

    {
    "grant_type": "authorization_code",
    "code": "8d535c<....>",
    "client_id": "50789",
    "client_secret": "c4497<...>",
    "redirect_uri": "http://localhost:8080",
    "scope": "read"
    }

     

    Any help will be highly appreciate :)

     

  • Avatar
    Bryan Flynn

    Hi Jens -- try setting client_id to the "Unique Identifier" value in your Zendesk's Admin > API > OAuth Clients dialog -- should look something like this (although 'test_oauth_client' will be a different value in your case):

    For this particular API call, the numeric ID of your client_id is not the value you want to pass -- you want to pass the alpha-numeric OAuth client value. Let me know how this works.

     

  • Avatar
    Jens Holmer

    It works !! Great Thanks alot. I believe I had tested that before. Might've been using wrong redirect along with it since one had changed it cause we didnt notice that it was possible to add more with newlines :). 

    Have nice day.

  • Avatar
    Nicole - Community Manager

    Glad to hear you got things working, Jens! 

    Also, I see that this is your first post - Welcome to the Zendesk Community! I encourage you to head over to the Introductions thread in The Lounge to introduce yourself to everyone and familiarize yourself with our Community Guidelines.

    We look forward to seeing you around the Community. Happy Zendesking!

  • Avatar
    Jens Holmer

    Thanks Nicole,

    I've actually worked 5+ years now with Zendesk - Jens is just a "incognito"-profile. It offers a great API. 

    What I am\was trying to do is to make customers authorize without having there access_token exposed. and that works now :) 

    I am still grubbling over 2 things though. I cant seem to find any information about what the authenticity_token is for ? And I cant seem to find a way to be able to retrieve an refresh_token ?

  • Avatar
    Bryan Flynn (Edited )

    Hi Jens -- the authenticity_token is useful if, say, you're in the Help Center and want to do AJAX calls back into Zendesk. It basically is a CSRF token that you can use on subsequent calls. If you don't have it, even though you're authenticated, you'll get a 403. You should be able to do something like this (get the token, then use it in a subsequent call):

    $.ajax('/api/v2/users/me.json').then(function(response){
      var token = response.user.authenticity_token;
      console.log(token);
      $.ajax({
        url: '/api/v2/community/posts/1150007/up.json',
        type: "POST",
        dataType: "application/json",
        headers: {
           "X-CSRF-Token": token
         }
      }).then(function(res){console.log(res)});
    });
     
    Know that a user already needs to be authenticated to use this technique. The Apps framework doesn't need this technique because the framework maintains the integrity of the session when making client.request calls.
     
    As far as OAuth refresh tokens go, Zendesk currently doesn't support those. Once you have a token, it doesn't expire unless explicitly revoked.
     

Please sign in to leave a comment.

Powered by Zendesk