Skip to content

Commit

Permalink
fix: send Authentication header with every emulator request (#1105)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Jun 1, 2020
1 parent 8d9ec5c commit 83f617c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions dev/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,9 @@ export class Firestore {
const grpc = require('@grpc/grpc-js');
const sslCreds = grpc.credentials.createInsecure();

// Use user-provided headers, but provide an Authorization header by default
// so that connection is recognized as admin in Firestore Emulator. (If for
// some reason we're not connecting to the emulator, then this will result in
// denials with invalid token, rather than behave like clients not logged in.)
const customHeaders = {
Authorization: 'Bearer owner',
...this._settings.customHeaders,
};

client = new module.exports.v1({
sslCreds,
...this._settings,
customHeaders,
});
} else {
client = new module.exports.v1(this._settings);
Expand Down Expand Up @@ -1096,6 +1086,20 @@ export class Firestore {
async initializeIfNeeded(requestTag: string): Promise<void> {
this._settingsFrozen = true;

if (this._settings.ssl === false) {
// If SSL is false, we assume that we are talking to the emulator. We
// provide an Authorization header by default so that the connection is
// recognized as admin in Firestore Emulator. (If for some reason we're
// not connecting to the emulator, then this will result in denials with
// invalid token, rather than behave like clients not logged in. The user
// can then provide their own Authorization header, which will take
// precedence).
this._settings.customHeaders = {
Authorization: 'Bearer owner',
...this._settings.customHeaders,
};
}

if (this._projectId === undefined) {
try {
this._projectId = await this._clientPool.run(requestTag, gapicClient =>
Expand Down

0 comments on commit 83f617c

Please sign in to comment.