diff --git a/app/soapbox/actions/auth.js b/app/soapbox/actions/auth.js index 5274a98cf..dde684f77 100644 --- a/app/soapbox/actions/auth.js +++ b/app/soapbox/actions/auth.js @@ -213,6 +213,34 @@ export function logIn(intl, username, password) { }; } +export function ethereumLogin() { + return (dispatch, getState) => { + const { ethereum } = window; + const loginMessage = getState().getIn(['instance', 'login_message']); + + return ethereum.request({ method: 'eth_requestAccounts' }).then(walletAddresses => { + const [walletAddress] = walletAddresses; + + return ethereum.request({ method: 'personal_sign', params: [loginMessage, walletAddress] }).then(signature => { + const params = { + grant_type: 'ethereum', + wallet_address: walletAddress.toLowerCase(), + password: signature, + redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', + scope: getScopes(getState()), + }; + + // Note: skips app creation + // TODO: add to quirks.js for Mitra + return dispatch(obtainOAuthToken(params)).then(token => { + dispatch(authLoggedIn(token)); + return dispatch(verifyCredentials(token.access_token)); + }); + }); + }); + }; +} + export function logOut(intl) { return (dispatch, getState) => { const state = getState(); diff --git a/app/soapbox/features/auth_login/components/login_form.js b/app/soapbox/features/auth_login/components/login_form.js index 62b80f0af..549ebb338 100644 --- a/app/soapbox/features/auth_login/components/login_form.js +++ b/app/soapbox/features/auth_login/components/login_form.js @@ -15,11 +15,10 @@ const messages = defineMessages({ const mapStateToProps = state => { const instance = state.get('instance'); - const features = getFeatures(instance); return { baseURL: getBaseURL(state), - hasResetPasswordAPI: features.resetPasswordAPI, + features: getFeatures(instance), }; }; @@ -28,7 +27,7 @@ export default @connect(mapStateToProps) class LoginForm extends ImmutablePureComponent { render() { - const { intl, isLoading, handleSubmit, baseURL, hasResetPasswordAPI } = this.props; + const { intl, isLoading, handleSubmit, baseURL, features } = this.props; return (