Comenzado el flujo oauth

hay que separar un poco todo
This commit is contained in:
Daniel Cortes
2020-06-23 05:04:51 -04:00
parent db3d0ce4d3
commit 72107bbc91
5 changed files with 120 additions and 12 deletions

View File

@@ -11,11 +11,6 @@ const reducer = (state, action) => {
...state,
user: action.user
}
case 'logout':
return {
...state,
user: action.user
}
default: return state;
}
};

View 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
}