| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 Copyright 2016 The LUCI Authors. All rights reserved. |
| 3 Use of this source code is governed under the Apache License, Version 2.0 |
| 4 that can be found in the LICENSE file. |
| 5 |
| 6 The `auth-signin` element displays sign-in/sign-out button, user email and |
| 7 avatar. |
| 8 It has a google-signin/google-signin-aware element under the hood that handles |
| 9 the actual OAuth logic. |
| 10 |
| 11 Usage: |
| 12 |
| 13 <auth-signin></auth-signin> |
| 14 |
| 15 Properties: |
| 16 authHeaders: Object, Use this in iron-ajax to set oauth2 headers. |
| 17 authResponse: Object, The raw gapi.auth2.AuthResponse object. |
| 18 clientId: String, The client id to authenticate |
| 19 profile: Object, Read Only, The email address and imageurl of the logged in
user. |
| 20 signedIn: Boolean, Read Only, if the user is logged in. |
| 21 |
| 22 Methods: |
| 23 signIn(): Signs the user in by popping up the authorization dialog. |
| 24 signOut(): Signs the user out. |
| 25 |
| 26 Events: |
| 27 auth-signin: Fired when the oauth handshake has completed and a user has log
ged in. |
| 28 --> |
| 29 |
| 30 <link rel="import" href="../../bower_components/google-signin/google-signin-awar
e.html"> |
| 31 <link rel="import" href="../../bower_components/polymer/polymer.html"> |
| 32 |
| 33 |
| 34 <dom-module id="auth-signin"> |
| 35 <template> |
| 36 <style> |
| 37 #avatar { |
| 38 border-radius: 5px; |
| 39 } |
| 40 #signinContainer { |
| 41 margin-top: 14px; |
| 42 } |
| 43 </style> |
| 44 |
| 45 <google-signin-aware id="aware" |
| 46 client-id="[[clientId]]" |
| 47 scopes="email" |
| 48 on-google-signin-aware-success="_onSignin" |
| 49 on-google-signin-aware-signed-out="_onSignout"> |
| 50 </google-signin-aware> |
| 51 |
| 52 <template is="dom-if" if="[[!signedIn]]"> |
| 53 <div id="signinContainer"> |
| 54 <a on-tap="signIn" href="#">Sign in</a> |
| 55 </div> |
| 56 </template> |
| 57 |
| 58 <template is="dom-if" if="[[signedIn]]"> |
| 59 <img id="avatar" src="[[profile.imageUrl]]" width="30" height="30"> |
| 60 <span>[[profile.email]]</span> |
| 61 <span>|</span> |
| 62 <a on-tap="signOut" href="#">Sign out</a> |
| 63 </template> |
| 64 </template> |
| 65 <script> |
| 66 'use strict'; |
| 67 Polymer({ |
| 68 is: 'auth-signin', |
| 69 properties: { |
| 70 authHeaders: { |
| 71 type: Object, |
| 72 computed: "_makeHeader(authResponse)", |
| 73 notify: true, |
| 74 }, |
| 75 authResponse: { |
| 76 type: Object, |
| 77 notify: true, |
| 78 }, |
| 79 clientId: { |
| 80 type: String, |
| 81 }, |
| 82 profile: { |
| 83 type: Object, |
| 84 readOnly: true |
| 85 }, |
| 86 signedIn: { |
| 87 type: Boolean, |
| 88 readOnly: true, |
| 89 value: false |
| 90 } |
| 91 }, |
| 92 |
| 93 _onSignin: function(e) { |
| 94 this._setSignedIn(true); |
| 95 var user = gapi.auth2.getAuthInstance().currentUser.get(); |
| 96 var profile = user.getBasicProfile(); |
| 97 this._setProfile({ |
| 98 email: profile.getEmail(), |
| 99 imageUrl: profile.getImageUrl() |
| 100 }); |
| 101 this.set("authResponse", user.getAuthResponse()); |
| 102 this.fire("auth-signin"); |
| 103 }, |
| 104 |
| 105 _onSignout: function(e) { |
| 106 this._setSignedIn(false); |
| 107 this._setProfile(null); |
| 108 }, |
| 109 |
| 110 _makeHeader: function(authResponse) { |
| 111 if (!authResponse) { |
| 112 return {}; |
| 113 } |
| 114 return { |
| 115 "authorization": authResponse.token_type + " " + authResponse.access_t
oken |
| 116 }; |
| 117 }, |
| 118 |
| 119 signIn: function() { |
| 120 this.$.aware.signIn(); |
| 121 }, |
| 122 |
| 123 signOut: function() { |
| 124 this.$.aware.signOut(); |
| 125 } |
| 126 }); |
| 127 </script> |
| 128 </dom-module> |
| OLD | NEW |