ibm-cloudibm-appid

App ID Custom Widget for a serverles SPA


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


Solution

  • 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.