Полагаю, вы следовали этому примеру https://marmelab.com/react-admin/Authentication.html,, что не не покрывает предоставление пароля OAuth2.
// in src/authProvider.js
import { AUTH_LOGIN } from 'react-admin';
export default (type, params) => {
if (type === AUTH_LOGIN) {
const { username, password } = params;
const request = new Request('https://mydomain.example.com/authenticate', {
method: 'POST',
body: JSON.stringify({ username, password }),
headers: new Headers({ 'Content-Type': 'application/json' }),
})
return fetch(request)
.then(response => {
if (response.status < 200 || response.status >= 300) {
throw new Error(response.statusText);
}
return response.json();
})
.then(({ token }) => {
localStorage.setItem('token', token);
});
}
return Promise.resolve();
}
Парни / девушки GitLab описывают, какие гранты они предоставляют.https://docs.gitlab.com/ee/api/oauth2.html#resource-owner-password-credentials-flow
Вот пример того, как вы можете получить токен доступа с помощью curl:
echo 'grant_type=password&username=<your_username>&password=<your_password>' > auth.txt
curl --data "@auth.txt" --request POST https://gitlab.com/oauth/token
С токеном доступа вы можете получить некоторую информацию от пользователя, которая также описана здесь:https://docs.gitlab.com/ee/api/oauth2.html#access-gitlab-api-with-access-token
Вот пример того, как вы можете получить информацию из GitLab с токеном доступа, который вы получили от предыдущего вызова, используя curl:
curl --header "Authorization: Bearer OAUTH-TOKEN" https://gitlab.com/api/v4/user
С некоторыми небольшими изменениями в реакции-admin пример, вы можете использовать поток паролей.
Здесь вы можете найти пример, который работает с GitLab:
https://gist.github.com/rilleralle/b28574ec1c4cfe10ec7b05809514344b
import { AUTH_LOGIN } from 'react-admin';
export default (type, params) => {
if (type === AUTH_LOGIN) {
const { username, password } = params;
const oAuthParams = {
grant_type: "password",
username,
password
}
const body = Object.keys(oAuthParams).map((key) => {
return encodeURIComponent(key) + '=' + encodeURIComponent(oAuthParams[key]);
}).join('&');
const request = new Request('https://gitlab.com/oauth/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
},
body
})
return fetch(request)
.then(response => {
if (response.status < 200 || response.status >= 300) {
throw new Error(response.statusText);
}
return response.json();
})
.then(( {access_token} ) => {
localStorage.setItem('token', access_token);
});
}
return Promise.resolve();
}
Надеюсь, это поможетвас.
Ура Ральф