-
Notifications
You must be signed in to change notification settings - Fork 6.6k
IAP Refresh Session Example. #1230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IAP Refresh Session Example. #1230
Conversation
5716b04
to
e391cdc
Compare
Updated, fixed lint. |
@tswast Tim, can you take a look at the frontend code? Thanks! |
iap/refresh/main.py
Outdated
import webapp2 | ||
|
||
|
||
class MainPage(webapp2.RequestHandler): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly prefer all new samples for App Engine standard use Flask over Webapp2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I didn't switch from jinja, do I need to?
iap/refresh/main.py
Outdated
nickname = None | ||
logout_url = None | ||
login_url = users.create_login_url('/') | ||
template_values = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style nit: please put a blank line between the end of a indented block and the following statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
iap/refresh/js/poll.js
Outdated
setTimeout(function() { | ||
var statusText = document.getElementById('status'); | ||
statusText.innerHTML = 'Polling'; | ||
var xhr = new XMLHttpRequest(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has pretty wide support at this point https://caniuse.com/#feat=fetch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, sound's like the fetch/promise polyfill won't be needed then, I'll switch it over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, please check my promise usage, not sure if it is correct.
iap/refresh/js/poll.js
Outdated
})(); | ||
|
||
// [START refresh_session] | ||
var iap_session_refresh_window = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd strongly prefer if you scoped this inside of a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jon, can you give me an example? my jsfoo is lacking.
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'use strict'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
iap/refresh/js/poll.js
Outdated
// limitations under the License. | ||
|
||
(function poll() { | ||
setTimeout(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer you give this function a name and invoke setTimeout separately, e.g.:
function pollForLoginState() {
...
}
setTimeout(pollForLoginState, 10000);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, changed to setInterval
iap/refresh/js/poll.js
Outdated
// [START refresh_session] | ||
var iap_session_refresh_window = null; | ||
|
||
function session_refresh_clicked() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
google style for function names in js is lowerCamelCase
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
iap/refresh/index.html
Outdated
@@ -0,0 +1,13 @@ | |||
<html><body> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the HTML style guide, this should have
<!DOCTYPE html>
The <html>
and <body>
tags are optional and should be removed.
Also, add <meta charset="utf-8">
and a <title>
tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
iap/refresh/js/poll.js
Outdated
poll(); | ||
}; | ||
xhr.send(null); | ||
}, 10000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add a comment saying 10000 means 10 seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
iap/refresh/js/poll.js
Outdated
else { | ||
statusText.innerHTML = xhr.statusText; | ||
} | ||
poll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like poll()
is always called. Maybe you could use setInterval instead of setTimeout
in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Comments addressed, PTAL. |
5962357
to
a4d8598
Compare
a4d8598
to
9a826db
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for frontend stuff.
Yes, jinja2 is the library to use for templates with Flask.
iap/refresh/main.py
Outdated
} | ||
|
||
template = jinja_environment.get_template('index.html') | ||
return template.render(template_values) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fun fact, jinja is built-in to flask so you can just do flask.render_template('index.html', template_values)
.
iap/refresh/main.py
Outdated
|
||
import os | ||
|
||
from flask import Flask |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import modules, not members. please just import flask
and use flask.Flask
.
No description provided.