0

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

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)。

编辑:我试图调用忘记密码页面但结果是错误的函数(状态代码 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);
        })
    })
}
4

1 回答 1

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);
        })
    })
}
于 2018-01-15T08:50:02.560 回答