-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthService.ts
More file actions
40 lines (32 loc) · 1.02 KB
/
Copy pathauthService.ts
File metadata and controls
40 lines (32 loc) · 1.02 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
import KJUR from "jsrsasign"
import Config from "./config"
import DeviceInfo from 'react-native-device-info';
/**
* AuthService class
*/
class AuthService {
// Just use the deviceId for the subject claim.
static getCurrentUsername(){
return DeviceInfo.getUniqueId();
}
static authChallenge(options, answerAuthenticationChallenge) {
// Header
var oHeader = { alg: 'HS256', typ: 'JWT' };
// Payload
var tNow = KJUR.jws.IntDate.get('now');
var tEnd = KJUR.jws.IntDate.get('now + 1day');
var oPayload = {
sub: this.getCurrentUsername(),
nonce: options.nonce,
iss: Config.issuer,
aud: Config.audience,
iat: tNow,
exp: tEnd,
};
var sHeader = JSON.stringify(oHeader);
var sPayload = JSON.stringify(oPayload);
var sJWT = KJUR.jws.JWS.sign("HS256", sHeader, sPayload, {utf8: Config.secret});
answerAuthenticationChallenge(sJWT);
}
}
export default AuthService;