├── .gitignore ├── favicon.ico ├── images └── icons │ ├── ms.png │ ├── f.svg │ └── g.svg ├── readme.md ├── LICENSE ├── index.html ├── app.css └── app.js /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tscanlin/serverless-authentication-gh-pages/gh-pages/favicon.ico -------------------------------------------------------------------------------- /images/icons/ms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tscanlin/serverless-authentication-gh-pages/gh-pages/images/icons/ms.png -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Demo page for serverless-authentication 2 | 3 | http://laardee.github.io/serverless-authentication-gh-pages/ 4 | 5 | simple authentication demo -------------------------------------------------------------------------------- /images/icons/f.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /images/icons/g.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Eetu Tuomala 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Serverless Authentication 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |

Serverless Authentication

15 |

UPDATING BACKEND

16 |

This is a frontend demonstration how Serverless Authentication boilerplate works.

17 |

Same version of boilerplate is used in this demo, it only authenticates, no personal data is saved to db.

18 |

Providers

19 |
20 | 21 | 22 | 23 | 24 |
25 |
26 | 27 |
28 |

Response

29 |
30 |

Test

31 |

Authorization token is valid for a 15 seconds, if auto refresh is checked, refresh token is used to request new authorization token

32 |
33 | 34 | 35 | Auto refresh token 36 |
37 |
38 |

See also serverless.com | sc5.io

39 |
40 | 50 | 51 | -------------------------------------------------------------------------------- /app.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: 'Lato', sans-serif; 3 | font-size: 16px; 4 | background-color: #efefef; 5 | } 6 | 7 | .main { 8 | padding: 20px; 9 | margin: 10px auto; 10 | max-width: 800px; 11 | background-color: white; 12 | -webkit-box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.2); 13 | -moz-box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.2); 14 | box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.2); 15 | } 16 | 17 | .notice { 18 | display: none; 19 | color: red; 20 | font-weight: bold; 21 | } 22 | 23 | h1 { 24 | font-size: 24px; 25 | margin-top: 0; 26 | } 27 | 28 | h2 { 29 | font-size: 16px; 30 | } 31 | 32 | .response { 33 | background-color: #cdcdcd; 34 | padding: 15px; 35 | overflow: auto; 36 | word-wrap: break-word; 37 | } 38 | 39 | button, .button { 40 | font-family: 'Lato', sans-serif; 41 | padding: 10px; 42 | font-size: 12px; 43 | font-weight: 700; 44 | text-transform: uppercase; 45 | border: 1px solid #ededed; 46 | background-color: #ededed; 47 | cursor: pointer; 48 | } 49 | 50 | .providers { 51 | display: -webkit-flex; 52 | display: flex; 53 | -webkit-flex-wrap: wrap; 54 | -ms-flex-wrap: wrap; 55 | flex-wrap: wrap; 56 | } 57 | 58 | button div.text, .button div.text { 59 | white-space: nowrap; 60 | } 61 | 62 | .providers button { 63 | background: transparent; 64 | height: 32px; 65 | padding: 3px; 66 | display: -webkit-flex; 67 | display: flex; 68 | margin-right: 10px; 69 | margin-bottom: 10px; 70 | -webkit-align-items: center; 71 | align-items: center; 72 | } 73 | 74 | .providers button div { 75 | display: inline-block; 76 | flex: auto; 77 | align-self: center; 78 | } 79 | 80 | .providers div.logo { 81 | height: 26px; 82 | width: 26px; 83 | } 84 | 85 | .providers div.text { 86 | padding: 0 10px; 87 | } 88 | 89 | .logout { 90 | margin-top: 20px; 91 | } 92 | 93 | button#facebook { 94 | background: #4c69ba; 95 | background: linear-gradient(#4c69ba, #3b55a0); 96 | color: white; 97 | border: none; 98 | } 99 | 100 | button#facebook div.logo { 101 | background-image: url("images/icons/f.svg"); 102 | height: 26px; 103 | width: 26px; 104 | } 105 | 106 | button#google div.logo { 107 | background: url("images/icons/g.svg"); 108 | height: 22px; 109 | width: 22px; 110 | margin-left: 2px; 111 | } 112 | 113 | button#microsoft div.logo { 114 | background: url("images/icons/ms.png"); 115 | background-size: 22px 22px; 116 | height: 22px; 117 | width: 22px; 118 | margin-left: 2px; 119 | } 120 | 121 | button#test { 122 | margin-bottom: 5px; 123 | } 124 | 125 | a { 126 | color: #454545; 127 | } -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var authenticationEndpoint = 'https://0ez31ged8j.execute-api.us-east-1.amazonaws.com/dev'; 4 | var contentApiEndpoint = 'https://6cr1cnmxc1.execute-api.us-east-1.amazonaws.com/dev'; 5 | function testToken() { 6 | var authorizationToken = localStorage.getItem('authorization_token'); 7 | if (authorizationToken) { 8 | $('#test-result').html('Loading...'); 9 | 10 | // set token to Authorization header 11 | $.ajax({ 12 | method: 'GET', 13 | url: contentApiEndpoint + '/test-token', 14 | headers: { 15 | Authorization: authorizationToken 16 | } 17 | }) 18 | .done(function (data) { 19 | $('#test-result').html(JSON.stringify(data)); 20 | }) 21 | .fail(function (error) { 22 | if($('#auto-refresh').prop('checked')) { 23 | $('#test-result').html('Refreshing token...'); 24 | refreshToken(); 25 | } else { 26 | $('#test-result').html('Unauthorized'); 27 | } 28 | }); 29 | } else { 30 | $('#test-result').html('Unauthorized'); 31 | } 32 | } 33 | 34 | function refreshToken() { 35 | $('#test-result').html('Loading...'); 36 | 37 | // refresh token 38 | $.ajax({ 39 | method: 'GET', 40 | url: authenticationEndpoint + '/authentication/refresh/' + localStorage.getItem('refresh_token') 41 | }) 42 | .done(function (data) { 43 | if (data.errorMessage) { 44 | $('#test-result').html(data.errorMessage); 45 | } else { 46 | saveResponse(data.authorization_token, data.refresh_token); 47 | testToken(); 48 | } 49 | }) 50 | .fail(function (error) { 51 | $('#test-result').html('Unauthorized'); 52 | }); 53 | } 54 | 55 | function saveResponse(authorization_token, refresh_token) { 56 | 57 | // Save token to local storage for later use 58 | if(authorization_token) { 59 | localStorage.setItem('authorization_token', authorization_token); 60 | } 61 | if(refresh_token) { 62 | localStorage.setItem('refresh_token', refresh_token); 63 | } 64 | 65 | $('#token').html('authorization_token:'+localStorage.getItem('authorization_token')+'
refresh_token:'+localStorage.getItem('refresh_token')); 66 | } 67 | 68 | function getPathFromUrl(url) { 69 | return url.split(/[?#]/)[0]; 70 | } 71 | 72 | function getQueryParams(qs) { 73 | qs = qs.split('+').join(' '); 74 | var params = {}, 75 | tokens, 76 | re = /[?&]?([^=]+)=([^&]*)/g; 77 | 78 | while (tokens = re.exec(qs)) { 79 | params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); 80 | } 81 | return params; 82 | } 83 | 84 | $(function () { 85 | $('.providers button').on('click', function (event) { 86 | var provider = $(event.currentTarget).attr('id'); 87 | $('#token').html('Loading...'); 88 | $('#test-result').html('Loading...'); 89 | window.location.href = authenticationEndpoint + '/authentication/signin/' + provider; 90 | }); 91 | 92 | $('#logout').on('click', function(event) { 93 | localStorage.removeItem('authorization_token'); 94 | localStorage.removeItem('refresh_token'); 95 | window.location.href = getPathFromUrl(window.location.href); 96 | }); 97 | 98 | var query = getQueryParams(document.location.search); 99 | if (query.error){ 100 | $('#token').html(query.error); 101 | localStorage.removeItem('authorization_token'); 102 | localStorage.removeItem('refresh_token'); 103 | } else { 104 | var aToken = query.authorization_token || ''; 105 | var rToken = query.refresh_token || ''; 106 | saveResponse(aToken, rToken); 107 | window.history.replaceState({authorization_token: ''}, 'serverless-authentication-gh-pages', '/serverless-authentication-gh-pages'); 108 | 109 | // trigger test token 110 | testToken(); 111 | } 112 | 113 | $('.testers #test').on('click', testToken); 114 | $('.testers #refresh').on('click', refreshToken); 115 | }); 116 | --------------------------------------------------------------------------------