Issue #25 Generando un challenge de verdad para oauth

This commit is contained in:
Daniel Cortes
2020-07-12 23:07:05 -04:00
parent 4794406c27
commit 4ec4b8f026
3 changed files with 119 additions and 102 deletions

5
package-lock.json generated
View File

@@ -12402,6 +12402,11 @@
"resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz",
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg=="
},
"sjcl": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.8.tgz",
"integrity": "sha512-LzIjEQ0S0DpIgnxMEayM1rq9aGwGRG4OnZhCdjx7glTaJtf4zRfpg87ImfjSJjoW9vKpagd82McDOwbRT5kQKQ=="
},
"slash": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz",

View File

@@ -22,6 +22,7 @@
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"react-tabs": "^3.1.1",
"sjcl": "^1.0.8",
"typescript": "^3.9.6"
},
"scripts": {

View File

@@ -1,14 +1,25 @@
import axios from "axios";
import sjcl from "sjcl";
import {getUser} from "./user_service";
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 = () => {
export const generate_challenge = () => {
const dictionary = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~';
let code = '';
for (let i = 0; i < 128; i++) {
let pos = Math.floor(Math.random() * dictionary.length);
code += dictionary.substring(pos, pos + 1);
}
let challenge = sjcl.codec.base64url.fromBits(sjcl.hash.sha256.hash(code));
return {
code: '5d2309e5bb73b864f989753887fe52f79ce5270395e25862da6940d5',
challenge: 'MChCW5vD-3h03HMGFZYskOSTir7II_MMTb8a9rJNhnI',
code: code,
challenge: challenge,
method: 'S256',
}
}