@@ -26,7 +26,7 @@ function getGoogleKeyByKeyId(keyId) {
2626 data += chunk . toString ( 'utf8' ) ;
2727 } ) ;
2828 res . on ( 'end' , ( ) => {
29- const { keys} = JSON . parse ( data ) ;
29+ const { keys } = JSON . parse ( data ) ;
3030 const pems = keys . reduce (
3131 ( pems , { n : modulus , e : exposant , kid } ) =>
3232 Object . assign ( pems , {
@@ -53,7 +53,7 @@ function getGoogleKeyByKeyId(keyId) {
5353}
5454
5555function getHeaderFromToken ( token ) {
56- const decodedToken = jwt . decode ( token , { complete : true } ) ;
56+ const decodedToken = jwt . decode ( token , { complete : true } ) ;
5757
5858 if ( ! decodedToken ) {
5959 throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND , `provided token does not decode as JWT` ) ;
@@ -62,7 +62,7 @@ function getHeaderFromToken(token) {
6262 return decodedToken . header ;
6363}
6464
65- async function verifyIdToken ( { id_token : token , id} , { clientId} ) {
65+ async function verifyIdToken ( { id_token : token , id } , { clientId } ) {
6666 if ( ! token ) {
6767 throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND , `id token is invalid for this user.` ) ;
6868 }
@@ -88,7 +88,7 @@ async function verifyIdToken({id_token: token, id}, {clientId}) {
8888 ) ;
8989 }
9090
91- if ( typeof id != " undefined" && jwtClaims . sub !== id ) {
91+ if ( typeof id != ' undefined' && jwtClaims . sub !== id ) {
9292 throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND , `auth data is invalid for this user.` ) ;
9393 }
9494
@@ -103,30 +103,35 @@ async function verifyIdToken({id_token: token, id}, {clientId}) {
103103}
104104
105105// Old way to validate an auth_token, only used for development purpose
106- function validateAuthToken ( { id, access_token} ) {
106+ function validateAuthToken ( { id, access_token } ) {
107107 return googleRequest ( 'tokeninfo?access_token=' + access_token ) . then ( response => {
108108 if ( response && ( response . sub == id || response . user_id == id ) ) {
109109 return ;
110110 }
111- throw new Parse . Error (
112- Parse . Error . OBJECT_NOT_FOUND , 'Google auth is invalid for this user.' ) ;
111+ throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND , 'Google auth is invalid for this user.' ) ;
113112 } ) ;
114113}
115114
116115// Returns a promise that fulfills if this user id is valid.
117- function validateAuthData ( { id, id_token, access_token} , options ) {
116+ function validateAuthData ( { id, id_token, access_token } , options ) {
117+ if ( ! id_token && ! access_token ) {
118+ throw new Parse . Error (
119+ Parse . Error . OBJECT_NOT_FOUND ,
120+ `id_token or access_token is missing for this user.`
121+ ) ;
122+ }
118123 // Returns a promise that fulfills if this user id is valid.
119124 if ( id_token ) {
120- return verifyIdToken ( { id, id_token} , options ) ;
125+ return verifyIdToken ( { id, id_token } , options ) ;
121126 } else {
122- return validateAuthToken ( { id, access_token} ) . then (
127+ return validateAuthToken ( { id, access_token } ) . then (
123128 ( ) => {
124129 // Validation with auth token worked
125130 return ;
126131 } ,
127132 ( ) => {
128133 // Try with the id_token param
129- return verifyIdToken ( { id, id_token : access_token } , options ) ;
134+ return verifyIdToken ( { id, id_token : access_token } , options ) ;
130135 }
131136 ) ;
132137 }
@@ -139,10 +144,9 @@ function validateAppId() {
139144
140145module . exports = {
141146 validateAppId : validateAppId ,
142- validateAuthData : validateAuthData
147+ validateAuthData : validateAuthData ,
143148} ;
144149
145-
146150// Helpers functions to convert the RSA certs to PEM (from jwks-rsa)
147151function rsaPublicKeyToPEM ( modulusB64 , exponentB64 ) {
148152 const modulus = new Buffer ( modulusB64 , 'base64' ) ;
0 commit comments