I have set the lifetime of my access and refresh token for testing. Now, I'm, wondering why the access token did not follow its lifetime and is still valid until the refresh token lifetime? I'm not sure if I set it right but here's how I configure the token lifetime:
var accessTokenLifetime = 300;
var absoluteRefreshTokenLifetime = 600;
resultClient = new Client
{
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
AllowOfflineAccess = true,
IdentityTokenLifetime = accessTokenLifetime,
AccessTokenLifetime = accessTokenLifetime,
UpdateAccessTokenClaimsOnRefresh = true,
RefreshTokenUsage = TokenUsage.OneTimeOnly,
RefreshTokenExpiration = TokenExpiration.Absolute,
AbsoluteRefreshTokenLifetime = absoluteRefreshTokenLifetime
};
Note: I removed some of the properties there.
Any thoughts?
The clients contains a 5 minute ClockSkew by default to support cases where the clocks in the different services are different.
You can set it in the Startup.ConfigureServices in your client applications, like this example to accept 1 minute skew. You can also set it to Zero if you like.
.AddMyJwtBearer(options =>
{
options.TokenValidationParameters.ClockSkew = TimeSpan.FromMinutes(1);
...
Related
I have a custom page, created with Shopify liquid -> https://shop.betterbody.co/pages/nazreen-joel-video-sales-letter-16-july
I have set the timer to load within 3seconds for the sales element to appear.
The question is, I would like to set an if/else condition to immediately show these sales element for repeat visitors. There is a timer.js that sets the time for the sales element to appear. If its a new visitor, timer will trigger, else server will not load the timer. I can't seem to find any solution online. Do I detect visitor IP? or is there any best solution to do this?
Here is the code inside theme.liquid,
{{ 'timer.js' | asset_url | script_tag }} .
Timer.js code:
$(document).ready(function(){
setTimeout(function() {
$(".refference").css({paddingTop: "350px"});
// $("#early-cta, #guarentee, #payments, #info, #details").show();
$("#early-cta, #guarentee, #payments, #info, #details").fadeIn(3000);
}, 3000);
});
Pls help.
You could look into localStorage to do this.
https://www.w3schools.com/htmL/html5_webstorage.asp
Localstorage is used to store data within the browser without any expiration date.
When a visitor visits the site for the first time, you could use localStorage to detect if the user has been to your site, if the user hasn’t, you run the timer, and set a variable that the user has visited.
Upon revisiting the site, you use localStorage and check against the variable to see if the user has been to your site or not, and trigger the script accordingly.
Expounding on #Jacob's answer and my comment, you can do what you need to do with JavaScript and localStorage.
So something like this to add:
function setVisited() {
// object to be added to localStorage
let obj = {
timestamp: new Date().getTime()
// add more stuff here if you need
// someValue: "foo",
// anotherValue: "bar"
}
// add object to localStorage
localStorage.setItem(
"hasVisited", // key that you will use to retrieve data
JSON.stringify(obj)
);
}
and something like this to retrieve:
function getVisited() {
return JSON.parse(localStorage.getItem("hasVisited"));
}
// returns: {timestamp: 1533398672593} or null
Also, as an additional condition to your event, you can choose to "expire" the user's localStorage value by checking the timestamp against the current timestamp and comparing it against a predefined expiration duration.
For example, if I wish to consider a visitor who has not returned 7 days as a new visitor:
let expiration = 86400 * 1000 * 7; // 7 days in milliseconds
function isNewVisitor() {
// get current timestamp
let timeNow = new Date().getTime();
let expired = true;
// if getVisited doesn't return null..
if (getVisited()) {
let timeDiff = timeNow - getVisited().timestamp;
expired = timeDiff > expiration;
}
// if the visitor is old and not expire, return true
if (!getVisited() || expired) {
return true;
} else {
return false;
}
}
So, to integrate with your current function, we will just check the condition before setting the timeout:
// let timeout be 3000 if the visitor is new
let timeout = isNewVisitor() ? 3000 : 0;
setTimeout(function() {
$(".refference").css({paddingTop: "350px"});
$("#early-cta, #guarentee, #payments, #info, #details").fadeIn(3000);
}, timeout);
// set the visited object for new visitors, update for old visitors
setVisited();
Check out the fiddle here: https://jsfiddle.net/fr9hjvc5/15/
In application.conf, parameters are set:
url = "jdbc:mysql://.../table_name"
user = ...
password = ...
driver = "com.mysql.jdbc.Driver"
connectionPool = HikariCP
queueSize = 25000
I am still receiving an error whenever the queue reaches 1000 items, meaning that the queueSize property is still the default value.
Task scala.slick.backend.DatabaseComponent$DatabaseDef$...
rejected from java.util.concurrent.ThreadPoolExecutor...
[Running, pool size = 20,
active threads = 20,
queued tasks = 1000,
completed tasks = 7507]
Not sure why it's not picking up your value, but you might want to try a different way of configuring.. you didn't say what version of Slick you are using. But please refer to the Slick 3.0.0 documentation. Try it using TypeSafe Config:
In your application.conf:
database {
dataSourceClass = "org.postgresql.ds.PGSimpleDataSource" // replace with mysql driver
properties = {
databaseName = "mydb"
user = "myuser"
password = "secret"
}
queueSize = 25000 // I've never changed that property, so not tested.
}
Then in scala:
val db = Database.forConfig("database")
Hope this works for you.
I have been trying like this -
// ================
// = set a Cookie for the users city =
// ================
function set($cityId = null){
$this->components[] = 'RequestHandler';
$this->components[] = 'Cookie';
$this->Cookie->name = 'Exampleoffers';
//$this->Cookie->time = 3600; // or '1 hour'
//$this->Cookie->path = '/bakers/preferences/';
$this->Cookie->domain = 'www.example.co.uk';
$this->Cookie->secure = false;
$this->Cookie->key = 'kkjdDqSI232qs*&sXOw!';
$cities = ($this->City->find('list'));
if($cities[$cityId]) {
$this->Cookie->write ("Deal.city_id", (int) $cityId, false, "+2 months");
} else {
$this->Cookie->write ("Deal.city_id", key($cities), false, "+2 months");
}
however, I am not sure if it is clashing with my Authsome cookie (?) or something else, but I am unable to read this value back.
Is there some way to specify which cookie you want to read() from in CakePHP?
Is there a way to have a cookie with 2 diffferent values of expiry times? - i.e. a cookie has User.id with a expiry of 1 week, and a Deal.city_id with a expiry of 2 months, say? Or am I right to think I DO need 2 cookies?
many thanks for any tips. It's cake 1.3 btw !
You can, remember cookies are saved on the system so if you only save the cookie one time on that system it will have the set values, however, you cannot have 2 cookies with the same name set, which means that when you go and save the cookies you'll have to do this:
$this->Cookie->write('Name1', $data, false, $time);
$this->Cookie->write('Name2', $data, false, $time);
If you don't, one will overwrite the other.
EDIT: Adding some links in case you have more doubts:
API page of CookieComponent: http://api13.cakephp.org/class/cookie-component
Cookbook page of CookieComponent: http://book.cakephp.org/view/1280/Cookies
First off, thank you #Moishe for the very useful API. I'm having a little timeout problem, maybe someone knows the answer. Here's how I open the channel:
var openChannel = function () {
var channel = new goog.appengine.Channel($('#token').val());
var socket = channel.open();
socket.onopen = function () {};
socket.onmessage = function (m) {
var message = JSON.parse(m.data);
// do stuff
};
socket.onerror = function (error) { alert(error); };
socket.onclose = openChannel;
};
openChannel();
This works fine, I post my messages and they go to the other clients pretty quickly. But if I stay on the page for roughly 15 minutes, the server loses track of my channel. In dev, it throws an error (which I saw was a known bug: http://www.mail-archive.com/google-appengine#googlegroups.com/msg44609.html). But in prod, it still ignores messages on that channel after about 15 minutes.
We fixed it by adding a setInterval(getSomeUrl, everyMinute) to the page, but we'd rather not have to do that. I noticed in Moishe's last commit for the trivia game sample that he took out a keep-alive. I didn't understand how he replaced it, and what he meant by onopen is reliable:
http://code.google.com/p/trivia-quiz/source/browse/trunk/src/index.html
Update: Server side code is
class Home(BaseHandler):
def get(self):
self.checkUser()
if self.user:
userId = self.user.user_id()
token = channel.create_channel(userId)
chatClients[userId] = token
self.model['token'] = token
players = self.checkChatRoom()
self.model['users'] = players
self.model['messages'] = map(lambda k:db.get(k), self.chat_room.messages) # TODO: Replace this line and the next with a query
self.model['messages'] = sorted(self.model['messages'], key=lambda m: m.timestamp, reverse=True)
self.writeTemplate('index.html')
BaseHandler is just a base class I use for all my GAE handlers, it provides checkUser which redirects if the user isn't logged in, and it provides writeTemplate which takes what's in self.model and writes it in a template. It's just a proof of concept, so no cache or anything else other than what's above.
i am trying to pull user's documents data from google docs using oauth,
but i cannot understand how to do it
- what's the purpose of oauth_verifier
- how to get the access token secret?
- if i try to use DocsService below, then i have a "server error"
- is there a clear tutorial for this? i cannot find any atm..
String oauth_verifier = req.getParameter("oauth_verifier");
String oauth_token = req.getParameter("oauth_token");
String oauthtokensecret = req.getParameter("oauth_token_secret");
GoogleOAuthParameters oauthparam = new GoogleOAuthParameters();
oauthparam.setOAuthConsumerKey("consumer key");
oauthparam.setOAuthConsumerSecret("secret");
oauthparam.setOAuthToken(oauth_token);
oauthparam.setOAuthTokenSecret(oauthtokensecret);
oauthparam.setOAuthVerifier(oauth_verifier);
OAuthHmacSha1Signer signer = new OAuthHmacSha1Signer();
GoogleOAuthHelper oauthhelper = new GoogleOAuthHelper(signer);
String accesstoken = "";
String accesstokensecret = "";
try {
oauthhelper.getUnauthorizedRequestToken(oauthparam);
accesstoken = oauthhelper.getAccessToken(oauthparam);
accesstokensecret = oauthparam.getOAuthTokenSecret();
// DocsService client = new DocsService("yourCompany-YourAppName-v1");
...
These may not be what you are looking for, since they are OAuth-specific and not google-related, but I found these "Getting started" articles very helpful:
http://oauth.net/documentation/getting-started
Turns out that I need to get the oauth_token_secret and reuse it later.
So (before redirecting user to google login page)
oauthhelper.getUnauthorizedRequestToken(oauthparam);
requesturl = oauthhelper.createUserAuthorizationUrl(oauthparam);
OAuthTokenSecret.tokenSecret = oauthparam.getOAuthTokenSecret();
resp.sendRedirect(requesturl);
Then after the user grants access and we have been redirected to oauth_callback url:
oauthparam.setOAuthToken(oauthtoken);
oauthparam.setOAuthVerifier(oauthverifier);
oauthparam.setOAuthTokenSecret(OAuthTokenSecret.tokenSecret);
oauthhelper.getAccessToken(oauthparam); // access token and access token secret are saved in oauthparam.
// access google service..
GoogleService googleService = new GoogleService( "cp", "test222");
googleService.setOAuthCredentials(oauthparam, signer);
BaseFeed resultFeed = googleService.getFeed(feedUrl, Feed.class);