9 Replies Latest reply on May 22, 2015 7:14 AM by Ryan Rutan

    Make REST API call using OAuth 2

    gfu

      Hi,

      We have a Liferay student portal and we want to setup a social network using Jive. The first thing we want to do is to retrieve notifications from Jive and display them on Student's page in Liferay portal. Jive REST API is the choice but I couldn't find any documentation on how to register an external client to make a Jive REST API call. What I know so far is an Add-On can be created to make REST API call, but how do I call this Add-on from Liferay portal?

       

      Thanks for any help!

        • Re: Make REST API call using OAuth 2

          Hi Gwowen Fu!  I think you'll get better visibility on this thread if you move it to the Jive Developers space.  To do so, click on 'Move' in the actions panel to the right of the conversation, and then start to type 'Developer' - you'll see the space and get the right eyeballs on your question.  Thanks!

            • Re: Make REST API call using OAuth 2
              gfu

              Thanks, question moved to Developer space.

                • Re: Make REST API call using OAuth 2
                  Ryan Rutan

                  Start with this document:

                  OAuth 2.0

                   

                  Create your add-on, install it...get your clientID/secret to obtain your access token and you are good to go...with either 3 legged or 2 legged OAuth.

                   

                  you can also check out the REST API & Webhooks - Developer Resources

                   

                  Hope that helps. =)

                    • Re: Make REST API call using OAuth 2
                      gfu

                      I have a simple add-on created from Jive Node SDK with "jive-sdk create app" command. I didn't make any code change. It works fine and I have Screen Shot 2015-05-05 at 1.48.20 PM.png

                      its clientID/secret. The missing part is how do I get the access token?

                       

                      Thank you!

                        • Re: Make REST API call using OAuth 2
                          pankaj.rajankar

                          I have the same question (in a different thread).

                          • Re: Make REST API call using OAuth 2
                            gfu

                            When I use Firefox RESTClient plugin to create token, it requires authorization endpoint, token endpoint, and redirection endpoint.

                             

                            When I run the curl command, tokens are generated:

                            curl -u 6ceeivjb6e83xv35ngsea50tbp6xr5oh.i:niwg4ot33eutwsxxlf5vivhclr6s27am.s -d'grant_type=password&username=gfu@devrygroup.com&password=xxxxxxxxxx' https://devrygroup.jiveon.com/oauth2/token

                            --

                            {"access_token":"8xp0yj4ud66jfj483vrgimmb4b433zszzq2d953u.t","refresh_token":"gc0myihfltegfmsrrdzfgvzyr6bkhwn5i9naeqse.r","token_type":"bearer","expires_in":"172799"}

                             

                            Why curl doesn't require endpoints? Can I use JavaScript to get token?

                             

                            Thank you!

                            Screen Shot 2015-05-05 at 2.14.43 PM.png

                              • Re: Make REST API call using OAuth 2
                                Ryan Rutan

                                You can use Javascript to initiate the dance, but usually it is a server-side resource the receives the tokens for the purposes of saving without breaching through to the client side.  The redirect end point is part of your Add-On’s meta.json that you uploaded to Jive.  If you are providing redirectURL again, it must match exactly the value of the one provided in the add-on.

                                 

                                Hope that helps.

                                  • Re: Make REST API call using OAuth 2
                                    gfu

                                    If my portal is at http://portal.devry.edu:8080/, do I replace "redirect_url" with "http://portal.devry.edu:8080"?

                                     

                                    When should I update "service_url"?

                                    My app is Jive hosted so the "clientUrl" in jiveclientconfiguration.json is not relevant, right?

                                     

                                    localhost:blank gwowen$ cat ./extension_src/meta.json

                                    {

                                        "package_version": "1.0",

                                        "id": "43d2bf51-604f-4bb1-b58b-a4587845f5f8",

                                        "type": "client-app",

                                        "name": "Add-on containing apps(s)",

                                        "description": "Apps: [Simple App Skeleton]",

                                        "minimum_version": "0080300000",

                                        "icon_16": "extension-16.png",

                                        "icon_48": "extension-48.png",

                                        "icon_128": "extension-128.png",

                                        "released_on": "2013-03-08T19:11:11.234Z",

                                        "service_url": "http://localhost:8090",

                                        "redirect_url": "%serviceURL%"

                                    }

                                    localhost:blank gwowen$ cat jiveclientconfiguration.json

                                    {

                                        "clientUrl": "http://localhost",

                                        "port": "8090",

                                        "development" : true,

                                        "logLevel" : "DEBUG",

                                        "suppressAddonRegistration" : true

                                    }


                                    Thank you!

                                • Re: Make REST API call using OAuth 2
                                  Ryan Rutan

                                  When your add-on is registered, your service receives a JSON payload with Jive instance details and the clientId/clientSecret issued by Jive.  If you want to get these manually, simply visit the Add-On page and click on the dropdown to the right of your add-on, and select View Client ID / Secret.

                                   

                                  If you are hosting your app in Jive, then you can set the clientUrl to "http:" and this will disable the registration response to a remote service on install, and you can manually grab the ID/secret from the menu (see above).

                                   

                                  redirect_url should be set to whatever URL you want the remote service's OAuth token granting page to redirect to on your end ... such that you can receive the request and capture the tokens.  Normally, your service will read the parameters and persist them into a DB of sorts to use whenever said user is trying to invoke an action on the remote system.

                                   

                                  The example I just described is considered 3-legged OAuth 2.0.  The curl client example above is using 2-legged OAuth 2.0.  When building web applications where you give the user control to authorize access to remote services to another service, this is traditionally done via 3-legged OAuth.  This is why they are different.  If your remote service supports 2-legged OAuth, then simply run a similar curl against said service and you should receive a similar response.

                                   

                                  I hope that helps clarify the outstanding questions on this thread.