@@ -57,44 +57,40 @@ class AtlasClient {
5757 return new this ( { url, jwt} ) ;
5858 }
5959
60- static async authenticateViaToken ( userAuthToken , options ) {
60+ static async requestAuthenticationCode ( userTag , options ) {
61+ const client = new this ( options || { } ) ;
62+ const [ user , org ] = client . parseTag ( userTag ) ;
63+ await client . fetch ( `/v1/login/send/${ org } /${ user } /` ) ;
64+ return smsCode => this . authenticateViaCode ( userTag , smsCode , options ) ;
65+ }
66+
67+ static async authenticateViaCode ( userTag , code , options ) {
6168 const client = new this ( options || { } ) ;
69+ const [ user , org ] = client . parseTag ( userTag ) ;
6270 const auth = await client . fetch ( '/v1/login/authtoken/' , {
6371 method : 'POST' ,
64- json : {
65- userauthtoken : userAuthToken
66- }
72+ json : { authtoken : [ org , user , code ] . join ( ':' ) }
6773 } ) ;
6874 await storage . putState ( credStoreKey , auth . token ) ;
6975 await storage . putState ( urlStoreKey , client . url ) ;
70-
71- return {
76+ return new this ( Object . assign ( {
7277 url : client . url ,
7378 jwt : auth . token
74- } ;
79+ } , options || { } ) ) ;
7580 }
7681
77- static async requestAuthenticationCode ( userTag , options ) {
78- const client = new this ( options || { } ) ;
79- const [ user , org ] = client . parseTag ( userTag ) ;
80- await client . fetch ( `/v1/login/send/${ org } /${ user } /` ) ;
81- return async smsCode => {
82- const auth = await this . authenticateViaCode ( userTag , smsCode , options ) ;
83- await storage . putState ( credStoreKey , auth . token ) ;
84- await storage . putState ( urlStoreKey , client . url ) ;
85- } ;
86- }
87-
88- static async authenticateViaCode ( userTag , code , options ) {
82+ static async authenticateViaToken ( userAuthToken , options ) {
8983 const client = new this ( options || { } ) ;
90- const [ user , org ] = client . parseTag ( userTag ) ;
91-
92- return client . fetch ( '/v1/login/authtoken/' , {
84+ const auth = await client . fetch ( '/v1/login/authtoken/' , {
9385 method : 'POST' ,
94- json : {
95- authtoken : [ org , user , code ] . join ( ':' )
96- }
86+ json : { userauthtoken : userAuthToken }
9787 } ) ;
88+ await storage . putState ( credStoreKey , auth . token ) ;
89+ await storage . putState ( urlStoreKey , client . url ) ;
90+ return new this ( Object . assign ( {
91+ url : client . url ,
92+ jwt : auth . token
93+ } , options || { } ) ) ;
9894 }
9995
10096 parseTag ( tag ) {
0 commit comments