This file contains hidden or 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
| const User = require('./user'); | |
| function get() { | |
| // check the db or something | |
| return new User('John', 'johndoe@somemail.com'); | |
| } | |
| exports.getUser = get; |
This file contains hidden or 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
| const repo = require('./userRepository'); | |
| class User { | |
| constructor(name, email) { | |
| this.name = name; | |
| this.email = email; | |
| } | |
| greet() { | |
| return `Hello, my name is ${name}`; |
This file contains hidden or 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
| import AWS from 'aws-sdk'; | |
| import { | |
| DocumentClient, | |
| PutItemInput, | |
| PutItemOutput, | |
| GetItemInput, | |
| QueryInput, | |
| ScanInput, | |
| DeleteItemInput, | |
| DeleteItemOutput, |
This file contains hidden or 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
| /** | |
| * wrapper for Validator.js | |
| * ref: | |
| * https://www.npmjs.com/package/validator | |
| */ | |
| import validator from 'validator'; | |
| /** | |
| * error messages | |
| */ |
This file contains hidden or 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
| /** | |
| * Mocha Test Template | |
| * refs ================================ | |
| * Mocha: https://mochajs.org | |
| * Chai: https://www.chaijs.com | |
| * Chai-As-Promised: https://www.chaijs.com/plugins/chai-as-promised/ | |
| * Sinon: https://sinonjs.org | |
| * debug: https://www.npmjs.com/package/debug | |
| */ | |
| import chai from 'chai'; |
This file contains hidden or 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
| /** | |
| * get selected fields of userinfo | |
| * @param { string } code | |
| * @return { object } | |
| */ | |
| async function getUserInfoFromCode(code) { | |
| const client = getOAuth2Client(); | |
| const data = await client.getToken(code); | |
| client.setCredentials(data.tokens); | |
| const userinfo = await client.request({ url: infoUrl }); |
This file contains hidden or 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
| import { OAuth2Client } from 'google-auth-library'; | |
| const p = console.log; | |
| /** APIs Explorer for OAuth2 v1: https://developers.google.com/apis-explorer/#p/oauth2/v1/ **/ | |
| const infoUrl = 'https://www.googleapis.com/oauth2/v1/userinfo?alt=JSON'; | |
| /** | |
| * information scope needed | |
| * reference: https://developers.google.com/identity/protocols/googlescopes | |
| * check: Google OAuth2 API, v2 | |
| */ |
This file contains hidden or 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
| import { OAuth2Client } from 'google-auth-library'; | |
| const p = console.log; | |
| /** | |
| * this establishes the connection | |
| * @return { OAuth2Client } | |
| */ | |
| function getOAuth2Client() { | |
| return new OAuth2Client('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'REDIRECT_URL'); | |
| } |
This file contains hidden or 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
| <script> | |
| // called by google client | |
| function onSignIn(googleUser) { | |
| var id_token = googleUser.getAuthResponse().id_token; | |
| // never log these out on a real app | |
| console.log('id_token: ', id_token); | |
| var profile = googleUser.getBasicProfile(); | |
| console.log('ID: ' + profile.getId()); | |
| console.log('Name: ' + profile.getName()); | |
| console.log('Image URL: ' + profile.getImageUrl()); |
This file contains hidden or 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
| <script src="https://apis.google.com/js/platform.js" async defer></script> | |
| <meta name="google-signin-client_id" content="<%= clientIdUrl %>" /> |