0

How to create custom IBM Cloud App ID login widget (cloud directory) for serverles secured SPA application?

Secured SPA application will use only IBM Cloud Functions via Gateway API.

Do i just have to implement https://github.com/ibm-cloud-security/appid-serversdk-nodejs as a cloud function to customize widget and keep my app serverles as i wish?

I could not find the clue from docs https://console.bluemix.net/catalog/services/app-id

Ideas?

@Jarkko

  • Do you want to use the App ID login widget? Or provide your own custom UI to collect the user's credentials yourself and just use the REST API to obtain a token using there credentials? – Moty Drimer Jan 04 '18 at 13:49

1 Answers1

1

If you don't want to use the App ID login widget, and instead collect the credentials yourself and use the ROP REST API from a cloud function. You can do something like this:

let request = require('request');

// put your App ID credentials here (can be found in App ID console):
let credentials = {
    "version": 3,
    "clientId": "xxxxx",
    "secret": "xxxxx",
    "tenantId": "xxxxx",
    "oauthServerUrl": "https://appid-oauth.eu-gb.bluemix.net/oauth/v3/xxxxx",
    "profilesUrl": "https://appid-profiles.eu-gb.bluemix.net"
};


function main(params) {
    return new Promise(function (resolve, reject) {
        request({
            url: credentials.oauthServerUrl + '/token',
            method: 'POST',
            auth: {
                username: credentials.clientId,
                password: credentials.secret
            },
            form: {

                grant_type: "password",
                // replace with actual credentials:
                username: "aaa@bbb.com",
                password: "11111111"
            }
        }, function (error, response, body) {
            resolve(response);
            // handle errors...
        });
    })
}

The response will be the App ID access token in this case.

Moty Drimer
  • 181
  • 4
  • Thank you Moty Drimer. I got it working, although i now have issues with Gateway API and cloud function invocation with parameters, but that is worth for another thread. – Jarkko Turpeinen Jan 08 '18 at 05:16