@mathrunet/masamune
Version:
Manages packages for the server portion (NodeJS) of the Masamune framework.
132 lines • 6.3 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const functions = __importStar(require("firebase-functions/v2"));
const api_1 = require("../lib/api");
/**
* After being redirected from [android_auth_code], you will get a refresh token to connect to Google's API.
* Please execute [android_auth_code] after registering the required information.
*
* [android_auth_code]からリダイレクトされた後、GoogleのAPIに接続するためのリフレッシュトークンを取得します。
* 必要情報を登録した後[android_auth_code]を実行してください。
*
* @param process.env.PURCHASE_ANDROID_REDIRECTURI
* Describe the absolute URL where [android_token] exists.
* You will be redirected to this URL to obtain a refresh token.
*
* [android_token]が存在する絶対URLを記述します。
* このURLにリダイレクトされリフレッシュトークンを取得できます。
*
* @param process.env.PURCHASE_ANDROID_CLIENTID
* Google's OAuth 2.0 client ID.
* Create an OAuth consent screen from the URL below.
* https://console.cloud.google.com/apis/credentials/consent
* Then create an OAuth 2.0 client ID from the credentials.
* https://console.cloud.google.com/apis/credentials
*
* GoogleのOAuth2.0のクライアントID。
* 下記のURLからOAuthの同意画面を作成します。
* https://console.cloud.google.com/apis/credentials/consent
* その後、認証情報からOAuth 2.0 クライアントIDを作成します。
* https://console.cloud.google.com/apis/credentials
*
* @param process.env.PURCHASE_ANDROID_CLIENTSECRET
* Google's OAuth 2.0 client secret.
* Create an OAuth consent screen from the URL below.
* https://console.cloud.google.com/apis/credentials/consent
* Then create an OAuth 2.0 client ID from the credentials.
* https://console.cloud.google.com/apis/credentials
*
* GoogleのOAuth2.0のクライアントシークレット。
* 下記のURLからOAuthの同意画面を作成します。
* https://console.cloud.google.com/apis/credentials/consent
* その後、認証情報からOAuth 2.0 クライアントIDを作成します。
* https://console.cloud.google.com/apis/credentials
*/
module.exports = (regions, options, data) => {
var _a, _b;
return functions.https.onRequest({
region: (_a = options.region) !== null && _a !== void 0 ? _a : regions,
timeoutSeconds: options.timeoutSeconds,
memory: options.memory,
minInstances: options.minInstances,
concurrency: options.concurrency,
maxInstances: options.maxInstances,
serviceAccount: (_b = options.serviceAccount) !== null && _b !== void 0 ? _b : undefined,
}, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
try {
const redirectUri = process.env.PURCHASE_ANDROID_REDIRECTURI;
const clientId = process.env.PURCHASE_ANDROID_CLIENTID;
const clientSecret = process.env.PURCHASE_ANDROID_CLIENTSECRET;
if (!req.query.code || !clientId || !clientSecret || !redirectUri) {
throw new functions.https.HttpsError("invalid-argument", "Query parameter is invalid.");
}
const resp = yield api_1.Api.post("https://accounts.google.com/o/oauth2/token", {
timeout: 30 * 1000,
data: {
"grant_type": "authorization_code",
"client_id": clientId,
"client_secret": clientSecret,
"redirect_uri": redirectUri,
"access_type": "offline",
"code": req.query.code,
},
});
if (!resp) {
throw new functions.https.HttpsError("data-loss", "Cannot get access token.");
}
const json = (yield resp.json());
if (json === null) {
throw new functions.https.HttpsError("data-loss", "Cannot get access token.");
}
console.log(json);
res.send(`RefreshToken:${json["refresh_token"]}`);
}
catch (err) {
console.error(err);
res.end();
}
}));
};
//# sourceMappingURL=android_token.js.map