-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathHome.js
More file actions
63 lines (58 loc) · 2.54 KB
/
Home.js
File metadata and controls
63 lines (58 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import React, { useState } from 'react';
import {
AuthorizationServiceConfiguration,
AuthorizationRequest, RedirectRequestHandler,
FetchRequestor, LocalStorageBackend, DefaultCrypto
} from '@openid/appauth';
import { NoHashQueryStringUtils } from './noHashQueryStringUtils';
import environment from './environment';
export const Home = () => {
const [error, setError] = useState(null);
const authorizationHandler = new RedirectRequestHandler(new LocalStorageBackend(), new NoHashQueryStringUtils(), window.location, new DefaultCrypto());
const redirect = () => {
AuthorizationServiceConfiguration.fetchFromIssuer(environment.OPServer, new FetchRequestor())
.then((response) => {
const authRequest = new AuthorizationRequest({
client_id: environment.clientId,
redirect_uri: environment.redirectURL,
scope: environment.scope,
response_type: AuthorizationRequest.RESPONSE_TYPE_CODE,
state: undefined,
// extras: environment.extra
});
authorizationHandler.performAuthorizationRequest(response, authRequest);
})
.catch(error => {
setError(error);
});
};
return (
<div className="container-fluid mt-3">
{
error && <div className="card text-white bg-danger mb-3">
<div className="card-body bg-danger">
<div className="card-body">
<p className="card-text">Error</p>
</div>
</div>
</div>
}
<div className="card">
<div className="card-body">
<h5 className="card-title">Welcome !!!</h5>
<p className="card-text">React Demo Application protected by
<a href="https://auth0.com" rel="noopener noreferrer" target="_blank">
Auth0
</a>
using
<a href="https://github.com/openid/AppAuth-JS" rel="noopener noreferrer"
target="_blank">
App Auth JS
</a>
</p>
<button type="button" className="btn btn-primary" onClick={redirect}>Login</button>
</div>
</div>
</div>
)
};