Comenzado el flujo oauth
hay que separar un poco todo
This commit is contained in:
45
src/services/auth_service.js
Normal file
45
src/services/auth_service.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import axios from "axios";
|
||||
|
||||
const current_host = `${window.location.protocol}//${window.location.host}`
|
||||
const oauth_url = `${process.env.REACT_APP_API_SERVER}/oauth`;
|
||||
const client_id = process.env["REACT_APP_CLIENT_ID"];
|
||||
|
||||
const generate_challenge = () => {
|
||||
return {
|
||||
code: '5d2309e5bb73b864f989753887fe52f79ce5270395e25862da6940d5',
|
||||
challenge: 'MChCW5vD-3h03HMGFZYskOSTir7II_MMTb8a9rJNhnI',
|
||||
method: 'S256',
|
||||
}
|
||||
}
|
||||
|
||||
export const obtain_code = () => {
|
||||
const challenge = generate_challenge()
|
||||
const params = {
|
||||
response_type: 'code',
|
||||
client_id: client_id,
|
||||
redirect_uri: `${current_host}/login`,
|
||||
scope: 'read write',
|
||||
code_challenge: challenge.challenge,
|
||||
code_challenge_method: challenge.method
|
||||
};
|
||||
const url = `${oauth_url}/authorize/?${new URLSearchParams(params).toString()}`;
|
||||
|
||||
return {
|
||||
redirect: url,
|
||||
code_verifier: challenge.code
|
||||
}
|
||||
}
|
||||
|
||||
export const get_auth = async (code, code_verifier) => {
|
||||
const params = {
|
||||
code: code,
|
||||
code_verifier: code_verifier,
|
||||
grant_type: 'authorization_code',
|
||||
redirect_uri: `${current_host}/login`,
|
||||
client_id: client_id,
|
||||
};
|
||||
const url = `${oauth_url}/token/`
|
||||
const response = await axios.post(url, new URLSearchParams(params));
|
||||
|
||||
return response.data
|
||||
}
|
||||
Reference in New Issue
Block a user