3 * Copyright 2015 Google Inc. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18 return new (P || (P = Promise))(function (resolve, reject) {
19 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
22 step((generator = generator.apply(thisArg, _arguments || [])).next());
25 Object.defineProperty(exports, "__esModule", { value: true });
26 const oauth2client_1 = require("./oauth2client");
27 class UserRefreshClient extends oauth2client_1.OAuth2Client {
28 constructor(optionsOrClientId, clientSecret, refreshToken, eagerRefreshThresholdMillis) {
29 const opts = (optionsOrClientId && typeof optionsOrClientId === 'object') ?
32 clientId: optionsOrClientId,
35 eagerRefreshThresholdMillis
38 clientId: opts.clientId,
39 clientSecret: opts.clientSecret,
40 eagerRefreshThresholdMillis: opts.eagerRefreshThresholdMillis
42 this._refreshToken = opts.refreshToken;
45 * Refreshes the access token.
46 * @param refreshToken An ignored refreshToken..
47 * @param callback Optional callback.
49 refreshTokenNoCache(refreshToken) {
50 const _super = Object.create(null, {
51 refreshTokenNoCache: { get: () => super.refreshTokenNoCache }
53 return __awaiter(this, void 0, void 0, function* () {
54 return _super.refreshTokenNoCache.call(this, this._refreshToken);
58 * Create a UserRefreshClient credentials instance using the given input
60 * @param json The input object.
64 throw new Error('Must pass in a JSON object containing the user refresh token');
66 if (json.type !== 'authorized_user') {
67 throw new Error('The incoming JSON object does not have the "authorized_user" type');
69 if (!json.client_id) {
70 throw new Error('The incoming JSON object does not contain a client_id field');
72 if (!json.client_secret) {
73 throw new Error('The incoming JSON object does not contain a client_secret field');
75 if (!json.refresh_token) {
76 throw new Error('The incoming JSON object does not contain a refresh_token field');
78 this._clientId = json.client_id;
79 this._clientSecret = json.client_secret;
80 this._refreshToken = json.refresh_token;
81 this.credentials.refresh_token = json.refresh_token;
83 fromStream(inputStream, callback) {
85 this.fromStreamAsync(inputStream).then(r => callback(), callback);
88 return this.fromStreamAsync(inputStream);
91 fromStreamAsync(inputStream) {
92 return __awaiter(this, void 0, void 0, function* () {
93 return new Promise((resolve, reject) => {
95 return reject(new Error('Must pass in a stream containing the user refresh token.'));
98 inputStream.setEncoding('utf8')
100 .on('data', (chunk) => s += chunk)
103 const data = JSON.parse(s);
115 exports.UserRefreshClient = UserRefreshClient;
116 //# sourceMappingURL=refreshclient.js.map