Skip to content

Commit 93f83f7

Browse files
committed
formatting
1 parent dfa8192 commit 93f83f7

1 file changed

Lines changed: 44 additions & 44 deletions

File tree

‎sample/oidc.js‎

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ var metadata = {
2121
end_session_endpoint: endSessionPath,
2222
};
2323

24-
function prependBaseUrlToMetadata(baseUrl){
25-
for(var name in metadata){
26-
metadata[name] = baseUrl + metadata[name];
24+
function prependBaseUrlToMetadata(baseUrl) {
25+
for (var name in metadata) {
26+
metadata[name] = baseUrl + metadata[name];
2727
}
2828
}
2929

@@ -40,48 +40,48 @@ var keys = {
4040
};
4141

4242
var claims = {
43-
"sub":"818727",
44-
"email":"AliceSmith@email.com",
45-
"email_verified":true,
46-
"role":["Admin","Geek"]
43+
"sub": "818727",
44+
"email": "AliceSmith@email.com",
45+
"email_verified": true,
46+
"role": ["Admin", "Geek"]
4747
};
4848

49-
function genAccessToken(){
49+
function genAccessToken() {
5050
return parseInt(Math.random().toString().replace("0.", "")).toString(16);
5151
}
5252

53-
function hashAccessToken(access_token){
53+
function hashAccessToken(access_token) {
5454
var hash = jsrsasign.crypto.Util.hashString(access_token, "sha256")
5555
var left = hash.substr(0, hash.length / 2);
5656
var left_b64u = jsrsasign.hextob64u(left);
5757
return left_b64u;
5858
}
5959

6060
function genIdToken(aud, nonce, access_token) {
61-
var now = parseInt(Date.now()/1000);
61+
var now = parseInt(Date.now() / 1000);
6262
var payload = {
63-
aud : aud,
64-
iss : metadata.issuer,
65-
nonce : nonce,
66-
sid : "37889234079034890",
67-
nbf : now,
68-
iat : now,
69-
exp : now + 300,
70-
idp : "some_idp",
71-
amr : [ "password" ]
63+
aud: aud,
64+
iss: metadata.issuer,
65+
nonce: nonce,
66+
sid: "37889234079034890",
67+
nbf: now,
68+
iat: now,
69+
exp: now + 300,
70+
idp: "some_idp",
71+
amr: ["password"]
7272
};
7373

7474
if (access_token) {
7575
payload.at_hash = hashAccessToken(access_token);
7676
payload.sub = claims.sub;
7777
}
7878
else {
79-
for(var key in claims){
79+
for (var key in claims) {
8080
payload[key] = claims[key];
81-
}
81+
}
8282
}
83-
84-
return jsrsasign.jws.JWS.sign(null, {alg: "RS256", kid: "1"}, payload, rsaKey.prvKeyObj);
83+
84+
return jsrsasign.jws.JWS.sign(null, { alg: "RS256", kid: "1" }, payload, rsaKey.prvKeyObj);
8585
}
8686

8787
function isOidc(response_type) {
@@ -113,56 +113,56 @@ function addFragment(url, name, value) {
113113

114114
return url;
115115
}
116-
116+
117117
module.exports = function(baseUrl, app) {
118118
prependBaseUrlToMetadata(baseUrl);
119-
120-
app.get(metadataPath, function (req, res) {
119+
120+
app.get(metadataPath, function(req, res) {
121121
res.json(metadata);
122122
});
123-
124-
app.get(signingKeysPath, function (req, res) {
123+
124+
app.get(signingKeysPath, function(req, res) {
125125
res.json(keys);
126126
});
127-
128-
app.get(authorizationPath, function (req, res) {
127+
128+
app.get(authorizationPath, function(req, res) {
129129
var response_type = req.query.response_type;
130-
130+
131131
var url = req.query.redirect_uri;
132-
133-
if (isOAuth(response_type)){
132+
133+
if (isOAuth(response_type)) {
134134
var access_token = genAccessToken();
135135
url = addFragment(url, "access_token", access_token);
136136
url = addFragment(url, "token_type", "Bearer");
137137
url = addFragment(url, "expires_in", "3600");
138138
url = addFragment(url, "scope", req.query.scope);
139139
}
140-
141-
if (isOidc(response_type)){
140+
141+
if (isOidc(response_type)) {
142142
url = addFragment(url, "id_token", genIdToken(req.query.client_id, req.query.nonce, access_token));
143143
url = addFragment(url, "session_state", "123");
144144
}
145-
145+
146146
var state = req.query.state;
147-
if (state){
147+
if (state) {
148148
url = addFragment(url, "state", state);
149149
}
150-
150+
151151
res.redirect(url);
152152
});
153-
154-
app.get(userInfoPath, function (req, res) {
153+
154+
app.get(userInfoPath, function(req, res) {
155155
res.json(claims);
156156
});
157-
158-
app.get(endSessionPath, function (req, res) {
157+
158+
app.get(endSessionPath, function(req, res) {
159159
var url = req.query.post_logout_redirect_uri;
160-
if (url){
160+
if (url) {
161161
var state = req.query.state;
162162
res.redirect(url + "?state=" + state);;
163163
}
164164
else {
165165
res.send("logged out");
166166
}
167-
});
167+
});
168168
}

0 commit comments

Comments
 (0)