I will describe with practical example, how to authenticate against MCS in Oracle JET using OAuth. This is based on sample app from my previous post - Oracle JET and Application Container Cloud (with MCS Integration) (download sample app from there). It would be useful to read through MCS documentation - Authenticating with OAuth in Individual REST Calls.
Oracle JET sample application provides login form:
If login is successful, REST call is done and MCS returns data:
In order to authenticate using OAuth, we need to use Application Key defined in MCS Mobile Backend:
Go to Mobile Backend settings screen and note down OAuth property values for Client ID and Client Secret. We are going to use these values in JET application, to initialize OAuth authentication:
There is one test user defined in Mobile Backend - redsam. We can use these user to login from JET over OAuth:
MCS offers to download SDK Java Script code, we could use it in JET application, to authenticate against MCS service through OAuth, Basic or Facebook login. Download SDK from getting started page:
I'm using mcs.js from MCS SDK, you could find helper method in this class - it executes REST POST to authenticate through OAuth and gets temporary access token in return. This token can be used for subsequent requests in the same session:
There is one more wrapper JS file - mbe.js. Here you define mobile backend connection keys. Authentication type is specified as oAuth:
Make sure to add mcs.js module into main.js paths:
Key point - mbe.authenticate() method (call it from JET module, make sure to reference mbe module in require block). Provide username/password and callbacks for login success and login failure:
In login success callback, I'm reading temporary token and passing it through header Authorization : Bearer. This token can be used for REST requests to MCS:
UI component is displayed when authentication is successful:
Oracle JET sample application provides login form:
If login is successful, REST call is done and MCS returns data:
In order to authenticate using OAuth, we need to use Application Key defined in MCS Mobile Backend:
Go to Mobile Backend settings screen and note down OAuth property values for Client ID and Client Secret. We are going to use these values in JET application, to initialize OAuth authentication:
There is one test user defined in Mobile Backend - redsam. We can use these user to login from JET over OAuth:
MCS offers to download SDK Java Script code, we could use it in JET application, to authenticate against MCS service through OAuth, Basic or Facebook login. Download SDK from getting started page:
I'm using mcs.js from MCS SDK, you could find helper method in this class - it executes REST POST to authenticate through OAuth and gets temporary access token in return. This token can be used for subsequent requests in the same session:
There is one more wrapper JS file - mbe.js. Here you define mobile backend connection keys. Authentication type is specified as oAuth:
Make sure to add mcs.js module into main.js paths:
Key point - mbe.authenticate() method (call it from JET module, make sure to reference mbe module in require block). Provide username/password and callbacks for login success and login failure:
In login success callback, I'm reading temporary token and passing it through header Authorization : Bearer. This token can be used for REST requests to MCS:
UI component is displayed when authentication is successful:
5 comments:
Hi Andrejus,
Great Post!!.
It would be great if you can attach the implemented sample application in this post.
Hi Andrejus,
Great Post!!.
Can you please post any URL to download the MCS SDK.
Hi,
I can't. You need to download MCS SDK from your MCS instance.
Regards,
Andrejus
Hi Andrejus,
Thanks for the reply.
Downloaded Cordova SDK for hybrid application.
Is it possible to provide the implemented application for code reference.
You can download source code from previous post, as mentioned in the top of this post.
Andrejus
Post a Comment