Skip to content

Commit

Permalink
feat: google wallet api authentication and authorization (#11)
Browse files Browse the repository at this point in the history
Add utils class for google authentication
  • Loading branch information
aahna-ashina committed May 23, 2022
1 parent 7178176 commit 9c169bb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/.env.local.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
BASIC_AUTH_USERNAME=username
BASIC_AUTH_PASSWORD=password

GOOGLE_APPLICATION_CREDENTIALS=
GOOGLE_WALLET_ISSUER_ID=
GOOGLE_WALLET_CLASS_ID=
GOOGLE_WALLET_USER_ID=
28 changes: 28 additions & 0 deletions server/utils/GoogleAuthUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { GoogleAuth } = require('google-auth-library')
const jwt = require('jsonwebtoken')

export class GoogleAuthUtils {

static retrieveCredentials() {
console.log('retrieveCredentials')

// Path to service account key file obtained from Google CLoud Console.
const serviceAccountFile = process.env.GOOGLE_APPLICATION_CREDENTIALS || '/path/to/key.json'

// Issuer ID obtained from Google Pay Business Console.
const issuerId = process.env.GOOGLE_WALLET_ISSUER_ID || '<issuer ID>'

// Developer defined ID for the wallet class.
const classId = process.env.GOOGLE_WALLET_CLASS_ID || 'test-generic-class-id'

// Developer defined ID for the user, eg an email address.
const userId = process.env.GOOGLE_WALLET_USER_ID || '[email protected]'

// ID for the wallet object, must be in the form `issuerId.userId` where userId is alphanumeric.
const objectId = `${issuerId}.${userId.replace(/[^\w.-]/g, '_')}-${classId}`

const credentials = require(serviceAccountFile)

return credentials
}
}

0 comments on commit 9c169bb

Please sign in to comment.