Skip to content

Commit

Permalink
feat: add .auth/login/done rule
Browse files Browse the repository at this point in the history
  • Loading branch information
manekinekko committed Jun 26, 2020
1 parent 31b2ac8 commit 53e2ea7
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
19 changes: 19 additions & 0 deletions identity_auth_login_done/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
],
"route": ".auth/login/done"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
53 changes: 53 additions & 0 deletions identity_auth_login_done/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const { response } = require("../utils");
const jwt = require("jsonwebtoken");

const jwtKey = "123";
const jwtExpirySeconds = 300;

module.exports = async function (context, req) {
const payload = {
...{
identityprovider: "github",
useridfromprovider: "1699357",
userid: "59cd31faa8c34919ac22c19af50482b8",
userdetails: "manekinekko",
isnewuser: "False",
existingroles: "",
},
nonce: context.invocationId,
iss: "https://localhost/",
aud: "https://localhost/",
};
const user_login_jwt = jwt.sign(payload, jwtKey, {
algorithm: "HS256",
expiresIn: jwtExpirySeconds,
});

context.res = response({
context,
status: 200,
cookies: [
{
name: "StaticWebAppsAuthContextCookie",
value: "deleted",
path: "/",
expires: new Date("Thu, 01 Jan 1970 00:00:00 GMT"),
domain: "localhost",
}
],
headers: {
"Content-Type": "text/html",
status: 200,
},
body: `
<title>Working...</title>
<form id="f" method="POST" action="http://localhost:4242/app/.auth/complete">
<input type="hidden" name="user_login_jwt" value="${user_login_jwt}" />
<noscript>
<p>Script is disabled.Click Submit to continue.</p>
<input type="submit" value="Submit" />
</noscript>
</form>
<script>f.submit();</script>`,
});
};
8 changes: 8 additions & 0 deletions users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"identityProvider": "github",
"userId": "59cd31faa8c34919ac22c19af50482b8",
"userDetails": "manekinekko",
"userRoles": ["anonymous", "authenticated"]
}
]

0 comments on commit 53e2ea7

Please sign in to comment.