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

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

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

@ -4,6 +4,8 @@ import { WebStorageStateStore } from 'oidc-client'
import { client } from 'config/clients'
import { AUTH_SERVICE } from 'config/routes'
import { ENV } from 'config/env'
export const getClientSettings = (): UserManagerSettings => ({
authority: AUTH_SERVICE,
automaticSilentRenew: true,
@ -11,7 +13,7 @@ export const getClientSettings = (): UserManagerSettings => ({
filterProtocolClaims: false,
loadUserInfo: false,
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_type: 'id_token token',
scope: 'openid',

Loading…
Cancel
Save