authscape 1.0.7 → 1.0.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "authscape",
3
- "version": "1.0.7",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -0,0 +1,68 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import axios from 'axios';
3
+ import querystring from "querystring";
4
+ import { setCookie } from 'nookies';
5
+
6
+ const signInValidator = async () => {
7
+
8
+ let codeVerifier = window.localStorage.getItem("verifier");
9
+ if (router.query.code != null && codeVerifier != null)
10
+ {
11
+ const headers = {'Content-Type': 'application/x-www-form-urlencoded'}
12
+
13
+ let queryString = querystring.stringify({
14
+ code: router.query.code,
15
+ grant_type: "authorization_code",
16
+ redirect_uri: window.location.origin + "/signin-oidc",
17
+ client_id: process.env.client_id,
18
+ client_secret: process.env.client_secret,
19
+ code_verifier: codeVerifier
20
+ });
21
+
22
+ let response = await axios.post(process.env.AUTHORITYURI + '/connect/token', queryString, {
23
+ headers: headers
24
+ });
25
+
26
+ window.localStorage.removeItem("verifier");
27
+
28
+ let domain = process.env.cookieDomain;
29
+
30
+ await setCookie(null, "access_token", response.data.access_token,
31
+ {
32
+ maxAge: 2147483647,
33
+ path: '/',
34
+ domain: domain,
35
+ secure: true
36
+ });
37
+
38
+ await setCookie(null, "expires_in", response.data.expires_in,
39
+ {
40
+ maxAge: 2147483647,
41
+ path: '/',
42
+ domain: domain,
43
+ secure: true
44
+ });
45
+
46
+ await setCookie(null, "refresh_token", response.data.refresh_token,
47
+ {
48
+ maxAge: 2147483647,
49
+ path: '/',
50
+ domain: domain,
51
+ secure: true
52
+ });
53
+
54
+
55
+ let redirectUri = localStorage.getItem("redirectUri")
56
+ localStorage.clear();
57
+ if (redirectUri != null)
58
+ {
59
+ window.location.href = redirectUri;
60
+ }
61
+ else
62
+ {
63
+ window.location.href = "/";
64
+ }
65
+ }
66
+ }
67
+
68
+ export default signInValidator;