@@ -799,33 +799,51 @@ function! s:GistGetAuthHeader()
799
799
800
800
redraw
801
801
echohl WarningMsg
802
- echo ' Gist.vim requires authorization to use the Github API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".'
802
+ echo ' Gist.vim requires authorization to use the GitHub API. These settings are stored in "~/.gist-vim". If you want to revoke, do "rm ~/.gist-vim".'
803
803
echohl None
804
- let password = inputsecret (" Github Password for " .g: github_user ." :" )
805
- if len (password) > 0
806
- let insecureSecret = printf (" basic %s" , webapi#base64#b64encode (g: github_user ." :" .password))
804
+ let password = inputsecret (" GitHub Password for " .g: github_user ." :" )
805
+ if len (password) == 0
806
+ let secret = ' '
807
+ let v: errmsg = ' Canceled'
808
+ return secrert
809
+ endif
810
+ let insecureSecret = printf (" basic %s" , webapi#base64#b64encode (g: github_user ." :" .password))
811
+ let res = webapi#http#post (g: github_api_url .' /authorizations' , webapi#json#encode ({
812
+ \ " scopes" : [" gist" ],
813
+ \ " note" : " Gist.vim on " .hostname (),
814
+ \ " note_url" : " http://www.vim.org/scripts/script.php?script_id=2423"
815
+ \} ), {
816
+ \ " Content-Type" : " application/json" ,
817
+ \ " Authorization" : insecureSecret,
818
+ \} )
819
+ let h = filter (res .header, ' v:val =~ "^X-GitHub-OTP: require"' )
820
+ if len (h )
821
+ let otp = inputsecret (" OTP:" )
822
+ if len (otp) == 0
823
+ let secret = ' '
824
+ let v: errmsg = ' Canceled'
825
+ return secrert
826
+ endif
807
827
let res = webapi#http#post (g: github_api_url .' /authorizations' , webapi#json#encode ({
808
828
\ " scopes" : [" gist" ],
809
829
\ " note" : " Gist.vim on " .hostname (),
810
830
\ " note_url" : " http://www.vim.org/scripts/script.php?script_id=2423"
811
831
\} ), {
812
832
\ " Content-Type" : " application/json" ,
813
833
\ " Authorization" : insecureSecret,
834
+ \ " X-GitHub-OTP" : otp,
814
835
\} )
815
- let authorization = webapi#json#decode (res .content)
816
- if has_key (authorization, ' token' )
817
- let secret = printf (" token %s" , authorization.token)
818
- call writefile ([secret], s: gist_token_file )
819
- if ! (has (' win32' ) || has (' win64' ))
820
- call system (" chmod go= " .s: gist_token_file )
821
- endif
822
- elseif has_key (authorization, ' message' )
823
- let secret = ' '
824
- let v: errmsg = authorization.message
836
+ endif
837
+ let authorization = webapi#json#decode (res .content)
838
+ if has_key (authorization, ' token' )
839
+ let secret = printf (" token %s" , authorization.token)
840
+ call writefile ([secret], s: gist_token_file )
841
+ if ! (has (' win32' ) || has (' win64' ))
842
+ call system (" chmod go= " .s: gist_token_file )
825
843
endif
826
- else
844
+ elseif has_key (authorization, ' message ' )
827
845
let secret = ' '
828
- let v: errmsg = ' Canceled '
846
+ let v: errmsg = authorization.message
829
847
endif
830
848
return secret
831
849
endfunction
0 commit comments