您不会使用 Azure Functions 来构建加载项,但您绝对可以将其与常规网站结合使用,以进行一些小型服务器端处理。
具体示例:对于我和同事构建的插件,我们需要获得用户的 GitHub 权限才能代表用户发布 Gists。GitHub 使用“授权代码授予类型”流程(请参阅https://developer.github.com/v3/oauth/),因此流程如下:
如果您想知道该代码是什么样的,请看这里:
var request = require('request');
module.exports = function (context, data) {
context.log('code: ' + data.code);
if ('code' in data) {
request.post({
url: 'https://github.com/login/oauth/access_token',
json: {
client_id: '################',
client_secret: '################',
redirect_uri: '################',
code: data.code
}
}, function (err, httpResponse, body) {
if (err) {
context.log('error: ' + err);
context.res = {
body: {
status: 500,
error: err
}
}
}
else {
context.res = { body: body };
}
context.done();
});
}
else {
context.res = {
status: 400,
body: { error: 'Please pass the GitHub code in the input object' }
};
context.done();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
572 次 |
| 最近记录: |