Skip to content

Commit

Permalink
Fixed issue when creating document without name. #85
Browse files Browse the repository at this point in the history
Removed "base64EncodeSafe_" as it is unnecessary.
  • Loading branch information
LaughDonor committed May 13, 2020
1 parent 6ba495f commit ab2a643
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getAuthToken_ (email, key, authUrl) {
const jwt = createJwt_(email, key, authUrl)

var options = {
'payload': 'grant_type=' + decodeURIComponent('urn:ietf:params:oauth:grant-type:jwt-bearer') + '&assertion=' + jwt
'payload': 'grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=' + jwt
}
const responseObj = new FirestoreRequest_(authUrl, null, options).post()
return responseObj.access_token
Expand Down Expand Up @@ -49,13 +49,13 @@ function createJwt_ (email, key, authUrl) {
'iat': nowSeconds
}

const jwtHeaderBase64 = base64EncodeSafe_(JSON.stringify(jwtHeader))
const jwtClaimBase64 = base64EncodeSafe_(JSON.stringify(jwtClaim))
const jwtHeaderBase64 = Utilities.base64EncodeWebSafe(JSON.stringify(jwtHeader))
const jwtClaimBase64 = Utilities.base64EncodeWebSafe(JSON.stringify(jwtClaim))

const signatureInput = jwtHeaderBase64 + '.' + jwtClaimBase64

const signature = Utilities.computeRsaSha256Signature(signatureInput, key)
const encodedSignature = base64EncodeSafe_(signature)
const encodedSignature = Utilities.base64EncodeWebSafe(signature)

return signatureInput + '.' + encodedSignature
}
12 changes: 0 additions & 12 deletions Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ function isNumberNaN_ (value) {
return typeof (value) === 'number' && isNaN(value)
}

/**
* Base64 Encodes a string without equals (=) symbol
*
* @private
* @param {string} string string to encode
* @returns {string} base64 encoded string (without =)
*/
function base64EncodeSafe_ (string) {
const encoded = Utilities.base64EncodeWebSafe(string)
return encoded.replace(/=/g, '')
}

/**
* Send HTTP request with provided options
*
Expand Down
14 changes: 12 additions & 2 deletions Write.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@
* @return {object} the Document object written to Firestore
*/
function createDocument_ (path, fields, request) {
request.addParam('currentDocument.exists', false)
return updateDocument_(path, fields, request)
const pathDoc = getDocumentFromPath_(path)
const documentId = pathDoc[1]

// Use UpdateDocument to create documents that may use special characters
if (documentId) {
request.addParam('currentDocument.exists', false)
return updateDocument_(path, fields, request)
}

const firestoreObject = createFirestoreDocument_(fields)
const newDoc = request.post(pathDoc[0], firestoreObject)
return unwrapDocumentFields_(newDoc)
}

/**
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firestore_google-apps-script",
"version": "25",
"version": "26",
"description": "A Google Apps Script library for accessing Google Cloud Firestore",
"homepage": "https://github.com/grahamearley/FirestoreGoogleAppsScript",
"bugs": "https://github.com/grahamearley/FirestoreGoogleAppsScript/issues",
Expand All @@ -11,7 +11,6 @@
"FirestoreRequest_",
"UrlFetchApp",
"Utilities",
"base64EncodeSafe_",
"cleanPath_",
"createDocument_",
"createFirestoreDocument_",
Expand Down

0 comments on commit ab2a643

Please sign in to comment.