用于App ID的IBM Cloud Function sign_up和forgot_password

时间:2018-01-15 08:01:24

标签: ibm-cloud ibm-appid ibm-cloud-functions

我可以使用以下云功能从云生成令牌

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);
        })
    })
}

如何在没有Node.js SDK和Express服务器的情况下使用App ID sign_up和forgot_password功能。换句话说,我想保持我的应用程序(SPA)无服务器并使用云功能。我已经尝试了,并阅读了解决方案的文档,但到目前为止没有运气(http 404)。

编辑:我试图调用忘记密码页面的功能,但结果是错误(statusCode 400)“缺少重定向”

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);
        })
    })
}

1 个答案:

答案 0 :(得分:0)

工作解决方案似乎如下:

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);
        })
    })
}