@@ -751,4 +751,197 @@ Security.prototype.getUserRights = function (userId, options, cb) {
751751  } ) ; 
752752} ; 
753753
754+ /** 
755+  * Create credentials of the specified <strategy> for the user <kuid>. 
756+  * 
757+  * @param  strategy 
758+  * @param  kuid 
759+  * @param  credentials 
760+  * @param  options 
761+  * @param  cb 
762+  * @returns  {Security } 
763+  */ 
764+ Security . prototype . createCredentials  =  function  ( strategy ,  kuid ,  credentials ,  options ,  cb )  { 
765+   if  ( ! cb  &&  typeof  options  ===  'function' )  { 
766+     cb  =  options ; 
767+     options  =  null ; 
768+   } 
769+ 
770+   this . kuzzle . query ( { controller : 'security' ,  action : 'createCredentials' } ,  { _id : kuid ,  strategy : strategy ,  body : credentials } ,  options ,  function ( err ,  res )  { 
771+     if  ( ! err )  { 
772+       cb  &&  cb ( null ,  res . result . _source ) ; 
773+     }  else  { 
774+       cb  &&  cb ( err ) ; 
775+     } 
776+   } ) ; 
777+ 
778+   return  this ; 
779+ } ; 
780+ 
781+ /** 
782+  * Delete credentials of the specified <strategy> for the user <kuid> . 
783+  * 
784+  * @param  strategy 
785+  * @param  kuid 
786+  * @param  options 
787+  * @param  cb 
788+  * @returns  {Security } 
789+  */ 
790+ Security . prototype . deleteCredentials  =  function  ( strategy ,  kuid ,  options ,  cb )  { 
791+   if  ( ! cb  &&  typeof  options  ===  'function' )  { 
792+     cb  =  options ; 
793+     options  =  null ; 
794+   } 
795+ 
796+   this . kuzzle . query ( { controller : 'security' ,  action : 'deleteCredentials' } ,  { strategy : strategy ,  _id : kuid } ,  options ,  typeof  cb  !==  'function'  ? null  : function ( err ,  res )  { 
797+     if  ( ! err )  { 
798+       cb  &&  cb ( null ,  res . result ) ; 
799+     }  else  { 
800+       cb  &&  cb ( err ) ; 
801+     } 
802+   } ) ; 
803+ 
804+   return  this ; 
805+ } ; 
806+ 
807+ /** 
808+  * Retrieve a list of accepted fields per authentication strategy. 
809+  * 
810+  * @param  options 
811+  * @param  cb 
812+  */ 
813+ Security . prototype . getAllCredentialFields  =  function  ( options ,  cb )  { 
814+   if  ( ! cb  &&  typeof  options  ===  'function' )  { 
815+     cb  =  options ; 
816+     options  =  null ; 
817+   } 
818+ 
819+   this . kuzzle . query ( { controller : 'security' ,  action : 'getAllCredentialFields' } ,  { } ,  options ,  typeof  cb  !==  'function'  ? null  : function ( err ,  res )  { 
820+     if  ( ! err )  { 
821+       cb  &&  cb ( null ,  res . result ) ; 
822+     }  else  { 
823+       cb  &&  cb ( err ) ; 
824+     } 
825+   } ) ; 
826+ } ; 
827+ 
828+ /** 
829+  * Retrieve the list of accepted field names by the specified <strategy>. 
830+  * 
831+  * @param  strategy 
832+  * @param  options 
833+  * @param  cb 
834+  */ 
835+ Security . prototype . getCredentialFields  =  function  ( strategy ,  options ,  cb )  { 
836+   if  ( ! cb  &&  typeof  options  ===  'function' )  { 
837+     cb  =  options ; 
838+     options  =  null ; 
839+   } 
840+ 
841+   this . kuzzle . query ( { controller : 'security' ,  action : 'getCredentialFields' } ,  { strategy : strategy } ,  options ,  typeof  cb  !==  'function'  ? null  : function ( err ,  res )  { 
842+     if  ( ! err )  { 
843+       cb  &&  cb ( null ,  res . result ) ; 
844+     }  else  { 
845+       cb  &&  cb ( err ) ; 
846+     } 
847+   } ) ; 
848+ } ; 
849+ 
850+ /** 
851+  * Get credential information of the specified <strategy> for the user <kuid>. 
852+  * 
853+  * @param  strategy 
854+  * @param  kuid 
855+  * @param  options 
856+  * @param  cb 
857+  */ 
858+ Security . prototype . getCredentials  =  function  ( strategy ,  kuid ,  options ,  cb )  { 
859+   if  ( ! cb  &&  typeof  options  ===  'function' )  { 
860+     cb  =  options ; 
861+     options  =  null ; 
862+   } 
863+ 
864+   this . kuzzle . query ( { controller : 'security' ,  action : 'getCredentials' } ,  { strategy : strategy ,  _id : kuid } ,  options ,  typeof  cb  !==  'function'  ? null  : function ( err ,  res )  { 
865+     if  ( ! err )  { 
866+       cb  &&  cb ( null ,  res . result ) ; 
867+     }  else  { 
868+       cb  &&  cb ( err ) ; 
869+     } 
870+   } ) ; 
871+ } ; 
872+ 
873+ /** 
874+  * Check the existence of the specified <strategy>’s credentials for the user <kuid>. 
875+  * 
876+  * @param  strategy 
877+  * @param  kuid 
878+  * @param  options 
879+  * @param  cb 
880+  */ 
881+ Security . prototype . hasCredentials  =  function  ( strategy ,  kuid ,  options ,  cb )  { 
882+   if  ( ! cb  &&  typeof  options  ===  'function' )  { 
883+     cb  =  options ; 
884+     options  =  null ; 
885+   } 
886+ 
887+   this . kuzzle . query ( { controller : 'security' ,  action : 'hasCredentials' } ,  { strategy : strategy ,  _id : kuid } ,  options ,  typeof  cb  !==  'function'  ? null  : function ( err ,  res )  { 
888+     if  ( ! err )  { 
889+       cb  &&  cb ( null ,  res . result ) ; 
890+     }  else  { 
891+       cb  &&  cb ( err ) ; 
892+     } 
893+   } ) ; 
894+ } ; 
895+ 
896+ /** 
897+  * Updates credentials of the specified <strategy> for the user <kuid>. 
898+  * 
899+  * @param  strategy 
900+  * @param  kuid 
901+  * @param  credentials 
902+  * @param  options 
903+  * @param  cb 
904+  * @returns  {Security } 
905+  */ 
906+ Security . prototype . updateCredentials  =  function  ( strategy ,  kuid ,  credentials ,  options ,  cb )  { 
907+   if  ( ! cb  &&  typeof  options  ===  'function' )  { 
908+     cb  =  options ; 
909+     options  =  null ; 
910+   } 
911+ 
912+   this . kuzzle . query ( { controller : 'security' ,  action : 'updateCredentials' } ,  { strategy : strategy ,  _id : kuid ,  body : credentials } ,  options ,  typeof  cb  !==  'function'  ? null  : function ( err ,  res )  { 
913+     if  ( ! err )  { 
914+       cb  &&  cb ( null ,  res . result ) ; 
915+     }  else  { 
916+       cb  &&  cb ( err ) ; 
917+     } 
918+   } ) ; 
919+ 
920+   return  this ; 
921+ } ; 
922+ 
923+ /** 
924+  * Validate credentials of the specified <strategy> for the user <kuid>. 
925+  * 
926+  * @param  strategy 
927+  * @param  kuid 
928+  * @param  credentials 
929+  * @param  options 
930+  * @param  cb 
931+  */ 
932+ Security . prototype . validateCredentials  =  function  ( strategy ,  kuid ,  credentials ,  options ,  cb )  { 
933+   if  ( ! cb  &&  typeof  options  ===  'function' )  { 
934+     cb  =  options ; 
935+     options  =  null ; 
936+   } 
937+ 
938+   this . kuzzle . query ( { controller : 'security' ,  action : 'validateCredentials' } ,  { strategy : strategy ,  _id : kuid ,  body : credentials } ,  options ,  typeof  cb  !==  'function'  ? null  : function ( err ,  res )  { 
939+     if  ( ! err )  { 
940+       cb  &&  cb ( null ,  res . result ) ; 
941+     }  else  { 
942+       cb  &&  cb ( err ) ; 
943+     } 
944+   } ) ; 
945+ } ; 
946+ 
754947module . exports  =  Security ; 
0 commit comments