aboutsummaryrefslogtreecommitdiff
path: root/catapult/third_party/polymer/components/google-signin/demo/index.html
blob: 0db7e5a97889d7c7c989bb32d43b083b4e62d6bf (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!doctype html>
<!-- Copyright (c) 2014 Google Inc. All rights reserved. -->
<html>
<head>
  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">

  <title>google-signin Demo</title>

  <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="../google-signin.html">
  <link rel="import" href="../google-signin-aware.html">

  <!-- Demo only styles -->
  <style>
    body {
      font-family: 'RobotoDraft', 'Roboto', sans-serif;
      line-height:1.2;
      vertical-align:middle;
      background: rgba(204, 204, 204, 0.31);
    }


    .map {
      background: whitesmoke;
      margin: .5rem -1.5rem 0 -1.5rem;
      padding: 0.5rem;
    }

    h1 {
      font-size: 2rem;
      font-weight:200;
      clear: both;
    }

    h1 strong {
      font-weight:300;
      color:#539D00;
    }

    h2 {
      font-size:.9rem;
      line-height:2.5;
      color:gray;
      font-weight:400;
      clear: both;
    }

    .showcase {
      display: inline-block;
      margin-right: 2rem;
      float: left;
    }
  </style>

</head>

<body>
  <p>A <code>&lt;google-signin&gt;</code> element looks like this button:</p>

  <p><google-signin brand="google" client-id="1054047045356-j8pgqgls9vdef3rl09hapoicumbte0bo.apps.googleusercontent.com"></google-signin>
or like this if plus scopes are present
  <google-signin brand="google-plus"></google-signin>
  </p>
  <p>Signin button can vary its appearance:</p>
  <p>Width:
    <google-signin brand="google" width="wide"></google-signin>
    <google-signin brand="google" width="iconOnly"></google-signin>
  Height:
    <google-signin brand="google" height="tall"></google-signin>
    <google-signin brand="google" height="standard"></google-signin>
    <google-signin brand="google" height="short"></google-signin>
  </p>
  <p>
  Theme:
    <google-signin brand="google" theme="dark"></google-signin>
    <google-signin brand="google" theme="light"></google-signin>
    <google-signin brand="google-plus" theme="dark"></google-signin>
    <google-signin brand="google-plus" theme="light"></google-signin>
    <google-signin brand="google-plus" theme="light" raised></google-signin>
  </p>
  <!-- Demo the ability to use the google-signin-aware element. -->
  <p><code>&lt;google-signin-aware&gt;</code> is a companion element.</p>
  <p>You can use it inside your components to request additional scopes.</p>
  <p>Every signin button will request all the scopes present in the document,
  and change its appearance to match</p>
  <p>For example, here is a signin-aware scope. You can change its scopes via popup</p>
  <dom-bind id="awareness">
    <template is="dom-bind">
      <div><code>&lt;google-signin-aware
        <div>scope=
          <select value="{{scope::change}}">
            <option value="">None</option>
            <option value="https://www.googleapis.com/auth/analytics">Google Analytics</option>
            <option value="https://www.googleapis.com/auth/plus.login">Google Plus view circles</option>
            <option value="https://www.googleapis.com/auth/youtube">YouTube</option>
            <option value="https://www.googleapis.com/auth/calendar">Calendar</option>
            <option value="profile">Profile info</option>
          </select>
        </div>
        <div>openid-prompt=
          <input type="checkbox" checked="{{openidPrompt.none::change}}">none
          <input type="checkbox" checked="{{openidPrompt.login::change}}">login
          <input type="checkbox" checked="{{openidPrompt.consent::change}}">consent
          <input type="checkbox"
              checked="{{openidPrompt.select_account::change}}">select_account
        </div>
        <div>offline=<input type="checkbox" checked="{{offline::change}}"></div>
        <div>initialized="<span>{{initialized}}</span>"</div>
        <div>signedIn="<span>{{signedIn}}</span>"</div>
        <div>isAuthorized="<span>{{isAuthorized}}</span>"</div>
        <div>needAdditionalAuth:"<span>{{needAdditionalAuth}}</span>"&gt;</div>
      </code></div>
      <p>Every new scope you select will be added to requested scopes.</p>
      <p>When you select a Google Plus scope, button will turn red.</p>
        <google-signin></google-signin>
      </p>
      <google-signin-aware
          scopes="{{scope}}"
          openid-prompt="{{openidPromptValue}}"
          initialized="{{initialized}}"
          signed-in="{{signedIn}}"
          offline="{{offline}}"
          is-authorized="{{isAuthorized}}"
          need-additional-auth="{{needAdditionalAuth}}"
          on-google-signin-aware-error="handleSignInError"
          on-google-signin-aware-success="handleSignIn"
          on-google-signin-offline-success="handleOffline"
          on-google-signin-aware-signed-out="handleSignOut"
          on-signed-in-changed="handleStateChange"
          on-initialized-changed="handleStateChange"></google-signin-aware>
      <p>User name:<span>{{userName}}</span></p>
      <p>Testing <code>google-signin-aware</code> events: <span>{{status}}</span></p>
      <p>Testing <code>google-signin-offline</code> events: <span>{{offlineCode}}</span></p>
      <p>Only display "not signed in" element after auth state is initialized (avoid flickering): <b hidden id="not-signed-in">Not signed in!</b></p>
      <p><button on-click="disconnect">Disconnect to start over</button></p>
    </template>
  </dom-bind>
  <script>
    var aware = document.querySelector('#awareness');
    if (!Polymer.Element) {
      aware = aware.querySelector('template');
    }

    aware.status = 'Not granted';
    aware.offlineCode = 'No offline login.';
    aware.userName = 'N/A';
    aware.openidPrompt = {};

    aware.handleSignInError = function(event) {
      this.status = JSON.stringify(event.detail);
    };
    aware.handleSignIn = function(response) {
      this.status = 'Signin granted';
      // console.log('[Aware] Signin Response', response);
      this.userName = gapi.auth2.getAuthInstance().currentUser.get().getBasicProfile().getName();
    };
    aware.handleOffline = function(response) {
      this.offlineCode = response.detail.code;
    };
    aware.handleSignOut = function(response) {
      this.status = 'Signed out';
      // console.log('[Aware] Signout Response', response);
      this.userName = 'N/A';
    };
    aware.disconnect = function() {
      var currentUser = gapi.auth2.getAuthInstance().currentUser.get();
      if (currentUser) {
        currentUser.disconnect();
      }
      gapi.auth2.getAuthInstance().signOut();
    };

    aware.handleStateChange = function(e) {
      var signedIn = e.target.signedIn;
      var initialized = e.target.initialized;
      if(initialized && !signedIn) {
        document.querySelector("#not-signed-in").removeAttribute("hidden");
      } else {
        document.querySelector("#not-signed-in").setAttribute("hidden", true);
      }
    };

    aware.addEventListener('openid-prompt-changed', function(e) {
      if (e.detail.value) {
        if (e.detail.path === 'openidPrompt.none') {
          aware.set('openidPrompt', {
            none: true,
            login: false,
            consent: false,
            select_account: false
          });
        } else {
          aware.set('openidPrompt.none', false);
        }
      }

      var values = [];
      Object.keys(aware.openidPrompt).forEach(function(k) {
        if (aware.openidPrompt[k]) {
          values.push(k);
        }
      });
      this.set('openidPromptValue', values.join(' '));
    });

  </script>
</body>
</html>