@@ -64,7 +64,7 @@ export default function useAuthorizedCredential({ data = {}, fields = [] }) {
6464 setError ( false ) ;
6565 } , [ credential ] ) ;
6666
67- const isOauth = data . schema === "Bearer " ;
67+ const isOauth = data . schema === "OAuth " ;
6868
6969 const authorized = useMemo ( ( ) => {
7070 if ( ! isOauth || ! ! data . refresh_token ) return true ;
@@ -107,27 +107,20 @@ export default function useAuthorizedCredential({ data = {}, fields = [] }) {
107107 method : "POST" ,
108108 data : { credential } ,
109109 } )
110- . then ( ( { success, redirect_url } ) => {
110+ . then ( ( { success, data } ) => {
111111 if ( ! success ) throw "error" ;
112112
113+ const { url, params } = data ;
113114 const form = document . createElement ( "form" ) ;
115+ form . action = url ;
114116 form . method = "GET" ;
115- form . action = redirect_url ;
116117 form . target = "_blank" ;
117118
118- let innerHTML = `
119- <input name="client_id" value="${ credential . client_id } " />
120- <input name="response_type" value="code" />
121- <input name="redirect_uri" value="${ restUrl ( "http-bridge/v1/oauth/redirect" ) } " />
122- <input name="access_type" value="offline" />
123- <input name="state" value="${ btoa ( addon ) } " />
124- ` ;
125-
126- if ( credential . scope ) {
127- innerHTML += `<input name="scope" value="${ credential . scope } " />` ;
128- }
129-
130- form . innerHTML = innerHTML ;
119+ form . innerHTML = Object . keys ( params ) . reduce ( ( html , name ) => {
120+ const value = params [ name ] ;
121+ if ( ! value ) return html ;
122+ return html + `<input name="${ name } " value="${ value } " />` ;
123+ } , "" ) ;
131124
132125 form . style . visibility = "hidden" ;
133126 document . body . appendChild ( form ) ;
0 commit comments