<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">You have option to pass the tokens from
local storage to the 'init' method of keycloak object. For example
you can use something like:<br>
<br>
keycloak.init({ <br>
token: 'yourAccessToken', <br>
refreshToken: 'yourRefreshToken',<br>
idToken: 'yourIdToken'<br>
});<br>
<br>
Another option is to not store anything in localStorage, but
instead after refresh the page re-authenticate the user again.
User won't need to login again and provide username/password,
because he should be logged automatically due to SSO (unless
session is expired). This is what our admin console and examples
are doing. Feel free to check them, especially angular example:
<a class="moz-txt-link-freetext" href="https://github.com/keycloak/keycloak/tree/master/examples/demo-template/angular-product-app">https://github.com/keycloak/keycloak/tree/master/examples/demo-template/angular-product-app</a><br>
<br>
Marek<br>
<br>
On 23.6.2015 20:06, Juan Diego wrote:<br>
</div>
<blockquote
cite="mid:CAJGEj6dgSsYyarUwgdRfcZ8bRZ7c7-_ZBm7yV-RR4y=mg0LYUw@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>Hi,<br>
<br>
</div>
After my user logs I am saving the token to a localstorage. I
am using angularjs by the way. <br>
<br>
</div>
<div>So if my user refreshes the page they still have the
session. As far as I can tell when you refresh the page, most
of the info of the object keycloak is null, except for the
realm and all the stuff you get form keycloak.json. Like if
you have never logged.<br>
<br>
</div>
<div>So I stored the token in my localStorage.<br>
<br>
</div>
<div>I am thinking 3 options basically.<br>
<br>
1)<br>
</div>
<div>Setting keycloak.token = localStorage.get("token"), and I
was trying to look for a function in that object to retrieve
all the other data, but I couldnt find any on the
documentation and looking at my console.log(keycloak)<br>
<br>
2)<br>
</div>
<div>Storing the whole object keycloak in localstorage, the
problem with this is that it will only store the properties
and obviously not the functions, so I was thinking that I
should manually set all the properties like this<br>
<br>
<pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9pt"><span style="color:rgb(102,14,122);font-weight:bold">clientId </span>= localStorageService.<span style="color:rgb(102,14,122);font-weight:bold">get</span>(<span style="color:rgb(0,128,0);font-weight:bold">'keycloak'</span>).<span style="color:rgb(102,14,122);font-weight:bold">clientId</span>;
<span style="color:rgb(102,14,122);font-weight:bold">idToken </span>= localStorageService.<span style="color:rgb(102,14,122);font-weight:bold">get</span>(<span style="color:rgb(0,128,0);font-weight:bold">'keycloak'</span>).<span style="color:rgb(102,14,122);font-weight:bold">idToken</span>;
<span style="color:rgb(102,14,122);font-weight:bold">idTokenParsed </span>= localStorageService.<span style="color:rgb(102,14,122);font-weight:bold">get</span>(<span style="color:rgb(0,128,0);font-weight:bold">'keycloak'</span>).<span style="color:rgb(102,14,122);font-weight:bold">idTokenParsed</span>;
<span style="color:rgb(102,14,122);font-weight:bold">realmAccess </span>= localStorageService.<span style="color:rgb(102,14,122);font-weight:bold">get</span>(<span style="color:rgb(0,128,0);font-weight:bold">'keycloak'</span>).<span style="color:rgb(102,14,122);font-weight:bold">realmAccess</span>;
</pre>
<pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9pt">3) Just check everything against the localstorage instead.
</pre>
<pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9pt">But I wont be able to use the functions from the object keyclaok, like updateToken.
</pre>
<pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9pt">I am kind of new to angular, as you can see too.
</pre>
<pre style="background-color:rgb(255,255,255);color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:9pt">Thanks,
</pre>
<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
keycloak-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/keycloak-user">https://lists.jboss.org/mailman/listinfo/keycloak-user</a></pre>
</blockquote>
<br>
</body>
</html>