ibm-cloudibm-appidibm-cloud-functions

IBM Cloud Function for App ID sign_up and forgot_password


I can generate token from cloud with following cloud function

const 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",
                username: params.uid,
                password: params.pwd
            }
        }, function (error, response, body) {
            resolve(response);
        })
    })
}

How i can use App ID sign_up and forgot_password functionality without Node.js SDK and Express server. In other words i'd like to keep my app (SPA) serverless and use cloud functions. I have tried, and read docs for a solution, but no luck so far (http 404).

Edit: function that i tried to invoke forgot password page but result is error (statusCode 400) "missing redirect"

const main = (params) => {
    return new Promise(function (resolve, reject) {
        request({
            url: credentials.oauthServerUrl + '/forgot_password',
            method: 'GET',
            form: {
                client_id: credentials.clientId,
                redirect_uri: "http://www.google.fi"
            }
        }, function (error, response, body) {
            resolve(response);
        })
    })
}

Solution

  • And the working solution seemed to be following:

    const request = require('request');
    const credentials = {
      "version": 3,
      "clientId": "xxx",
      "secret": "xxx",
      "tenantId": "xxx",
      "oauthServerUrl": "https://appid-oauth.eu-gb.bluemix.net/oauth/v3/xxx/cloud_directory/forgot_password"
    }
    const main = (params) => {
        return new Promise(function (resolve, reject) {
            request({
                url: credentials.oauthServerUrl 
                    + '?client_id=' + credentials.clientId 
                        + '&redirect_uri=http://www.my.domain'
                    ,
                method: 'GET'
            }, function (error, response, body) {
                resolve(response);
            })
        })
    }