authscape 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/services/signInValidator.js +65 -0
package/package.json
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import querystring from "querystring";
|
|
4
|
+
import { setCookie } from 'nookies';
|
|
5
|
+
|
|
6
|
+
export default function signInValidator() {
|
|
7
|
+
let codeVerifier = window.localStorage.getItem("verifier");
|
|
8
|
+
if (router.query.code != null && codeVerifier != null)
|
|
9
|
+
{
|
|
10
|
+
const headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
|
11
|
+
|
|
12
|
+
let queryString = querystring.stringify({
|
|
13
|
+
code: router.query.code,
|
|
14
|
+
grant_type: "authorization_code",
|
|
15
|
+
redirect_uri: window.location.origin + "/signin-oidc",
|
|
16
|
+
client_id: process.env.client_id,
|
|
17
|
+
client_secret: process.env.client_secret,
|
|
18
|
+
code_verifier: codeVerifier
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
let response = await axios.post(process.env.AUTHORITYURI + '/connect/token', queryString, {
|
|
22
|
+
headers: headers
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
window.localStorage.removeItem("verifier");
|
|
26
|
+
|
|
27
|
+
let domain = process.env.cookieDomain;
|
|
28
|
+
|
|
29
|
+
await setCookie(null, "access_token", response.data.access_token,
|
|
30
|
+
{
|
|
31
|
+
maxAge: 2147483647,
|
|
32
|
+
path: '/',
|
|
33
|
+
domain: domain,
|
|
34
|
+
secure: true
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
await setCookie(null, "expires_in", response.data.expires_in,
|
|
38
|
+
{
|
|
39
|
+
maxAge: 2147483647,
|
|
40
|
+
path: '/',
|
|
41
|
+
domain: domain,
|
|
42
|
+
secure: true
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
await setCookie(null, "refresh_token", response.data.refresh_token,
|
|
46
|
+
{
|
|
47
|
+
maxAge: 2147483647,
|
|
48
|
+
path: '/',
|
|
49
|
+
domain: domain,
|
|
50
|
+
secure: true
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
let redirectUri = localStorage.getItem("redirectUri")
|
|
55
|
+
localStorage.clear();
|
|
56
|
+
if (redirectUri != null)
|
|
57
|
+
{
|
|
58
|
+
window.location.href = redirectUri;
|
|
59
|
+
}
|
|
60
|
+
else
|
|
61
|
+
{
|
|
62
|
+
window.location.href = "/";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|