forked from nation3/mobile-passport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: google wallet api authentication and authorization (#11)
Add utils class for google authentication
- Loading branch information
1 parent
7178176
commit 9c169bb
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |