fix(#2227): fix post request to auth

keep-around/78728aaea3c73604b730226a5c18add5a7bcecd6
Andrei Dekterev 4 years ago
parent 7631931f01
commit e57e645fc6
  1. 32
      src/features/AuthServiceApp/components/Login/hooks.tsx
  2. 17
      src/features/AuthServiceApp/components/Login/index.tsx
  3. 4
      src/features/AuthServiceApp/requests/authСheck.tsx
  4. 4
      src/features/AuthStore/helpers.tsx

@ -6,10 +6,11 @@ import {
} from 'react' } from 'react'
import { loginCheck } from 'features/AuthServiceApp/requests/authСheck' import { loginCheck } from 'features/AuthServiceApp/requests/authСheck'
import { authorize } from 'features/AuthServiceApp/requests/auth'
import { getApiUrl } from 'features/AuthServiceApp/config/routes' import { getApiUrl } from 'features/AuthServiceApp/config/routes'
import { useLexicsStore } from 'features/LexicsStore' import { useLexicsStore } from 'features/LexicsStore'
import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields' import { useAuthFields } from 'features/AuthServiceApp/hooks/useAuthFields'
import { getClientSettings } from 'features/AuthStore/helpers'
import { useLocation } from 'react-router' import { useLocation } from 'react-router'
const url = getApiUrl('/authorize') const url = getApiUrl('/authorize')
@ -22,6 +23,7 @@ export const useLoginForm = () => {
const [isModalOpen, setIsModalOpen] = useState(false) const [isModalOpen, setIsModalOpen] = useState(false)
const formRef = useRef<HTMLFormElement>(null) const formRef = useRef<HTMLFormElement>(null)
const { const {
email, email,
error: formError, error: formError,
@ -43,8 +45,19 @@ export const useLoginForm = () => {
const handleModalOpen = () => { const handleModalOpen = () => {
setIsModalOpen(true) setIsModalOpen(true)
} }
const submitForm = () => formRef.current?.submit()
const redirect_url = new URLSearchParams(location.search).get('redirect_uri')
const {
client_id,
redirect_uri,
response_mode,
response_type,
scope,
} = getClientSettings()
const redirect_url = new URLSearchParams(location.search).get('redirect_uri') || '' const currentRedirectUrl = redirect_url ?? redirect_uri
const handleError = (error: string) => { const handleError = (error: string) => {
setAuthError(error) setAuthError(error)
@ -59,14 +72,9 @@ export const useLoginForm = () => {
email, email,
lang, lang,
password, password,
redirect_url, currentRedirectUrl,
) )
await (authorize( submitForm()
email,
lang,
password,
redirect_url,
))
} catch (err) { } catch (err) {
handleError(String(err)) handleError(String(err))
} }
@ -78,6 +86,7 @@ export const useLoginForm = () => {
return { return {
authError, authError,
client_id,
email, email,
formError, formError,
formRef, formRef,
@ -86,11 +95,16 @@ export const useLoginForm = () => {
isFetching, isFetching,
isModalOpen, isModalOpen,
isSubmitDisabled, isSubmitDisabled,
lang,
onEmailBlur, onEmailBlur,
onEmailChange, onEmailChange,
onPasswordBlur, onPasswordBlur,
onPasswordChange, onPasswordChange,
password, password,
redirect_uri: currentRedirectUrl,
response_mode,
response_type,
scope,
setIsModalOpen, setIsModalOpen,
url, url,
} }

@ -25,25 +25,36 @@ import { RegisterButton } from './styled'
const Login = () => { const Login = () => {
const { const {
authError, authError,
client_id,
email, email,
formError, formError,
formRef,
handleModalOpen, handleModalOpen,
handleSubmit, handleSubmit,
isFetching, isFetching,
isModalOpen, isModalOpen,
isSubmitDisabled, isSubmitDisabled,
lang,
onEmailBlur, onEmailBlur,
onEmailChange, onEmailChange,
onPasswordBlur, onPasswordBlur,
onPasswordChange, onPasswordChange,
password, password,
redirect_uri,
response_mode,
response_type,
scope,
setIsModalOpen, setIsModalOpen,
url,
} = useLoginForm() } = useLoginForm()
return ( return (
<CenterBlock> <CenterBlock>
<Logo /> <Logo />
<Form <Form
method='POST'
ref={formRef}
action={url}
onSubmit={handleSubmit} onSubmit={handleSubmit}
> >
<BlockTitle t='step_title_login' /> <BlockTitle t='step_title_login' />
@ -68,6 +79,12 @@ const Login = () => {
onChange={onPasswordChange} onChange={onPasswordChange}
onBlur={onPasswordBlur} onBlur={onPasswordBlur}
/> />
<input type='hidden' name='client_id' value={client_id} />
<input type='hidden' name='response_mode' value={response_mode} />
<input type='hidden' name='response_type' value={response_type} />
<input type='hidden' name='scope' value={scope} />
<input type='hidden' name='lang' value={lang} />
<input type='hidden' name='redirect_uri' value={redirect_uri} />
</InputGroup> </InputGroup>
<ButtonsBlock> <ButtonsBlock>

@ -23,7 +23,7 @@ export const loginCheck = async (
email: string, email: string,
lang: string, lang: string,
password: string, password: string,
redirect_url: string, redirect_uri: string | undefined,
) => { ) => {
const { const {
client_id, client_id,
@ -35,7 +35,7 @@ export const loginCheck = async (
const paramsUrl = { const paramsUrl = {
client_id, client_id,
lang, lang,
redirect_uri: redirect_url, redirect_uri,
response_mode, response_mode,
response_type, response_type,
scope, scope,

@ -4,6 +4,8 @@ import { WebStorageStateStore } from 'oidc-client'
import { client } from 'config/clients' import { client } from 'config/clients'
import { AUTH_SERVICE } from 'config/routes' import { AUTH_SERVICE } from 'config/routes'
import { ENV } from 'config/env'
export const getClientSettings = (): UserManagerSettings => ({ export const getClientSettings = (): UserManagerSettings => ({
authority: AUTH_SERVICE, authority: AUTH_SERVICE,
automaticSilentRenew: true, automaticSilentRenew: true,
@ -11,7 +13,7 @@ export const getClientSettings = (): UserManagerSettings => ({
filterProtocolClaims: false, filterProtocolClaims: false,
loadUserInfo: false, loadUserInfo: false,
metadataUrl: `${AUTH_SERVICE}/.well-known/openid-configuration${client.auth.metaDataUrlParams || ''}`, metadataUrl: `${AUTH_SERVICE}/.well-known/openid-configuration${client.auth.metaDataUrlParams || ''}`,
redirect_uri: `${window.origin}/redirect`, redirect_uri: ENV === 'staging' ? `https://${ENV}.${client.name}.tv/redirect` : `https://${client.name}.tv/redirect`,
response_mode: 'query', response_mode: 'query',
response_type: 'id_token token', response_type: 'id_token token',
scope: 'openid', scope: 'openid',

Loading…
Cancel
Save