<div dir="ltr">Hello Stian,<div><br></div><div><div>I was testing this today. My problem is that the keycloak.js script assumes  that the client application is hosted in a app/web server. I&#39;m trying to build a html 5 based app for smartphones. So there is no way to use the redirect functionality, I need a way to provide to keycloak a username and password and receive as response the token id.  </div>
</div><div><br></div><div>Do you think that is possible? Is there any example available.</div><div><br></div><div>Thanks.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Mar 10, 2014 at 10:34 AM, Stian Thorgersen <span dir="ltr">&lt;<a href="mailto:stian@redhat.com" target="_blank">stian@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
We have a JS library, it&#39;s available at <a href="http://localhost:8080/js/keycloak.js" target="_blank">http://localhost:8080/js/keycloak.js</a>. There&#39;s no documentation for it yet, and the example needs a bit of TLC, but the example is customer-app-js and will be included in the alpha3 downloads that is due this week.<br>

<br>
A quick overview to get you started:<br>
<br>
Keycloak constructor takes a single object with the following properties:<br>
<br>
* client_id (required) - the name of the application/client in the admin console<br>
* client_secret (optional) - not recommended, instead select public client option for your application/client in the admin console<br>
* realm (required)<br>
* url (optional) - the base url of the server, if not specified it will infer it from the url of the keycloak.js script<br>
* onload (optional) - valid options: login-required, check-sso. Login required will redirect to login form when init is called. Check-sso will also redirect to login form, but won&#39;t display login form (used to check if user is logged into to sso realm)<br>

<br>
For example:<br>
<br>
  var keycloak = Keycloak({ client_id: &#39;myapp&#39;, realm: &#39;myrealm&#39; })<br>
  keycloak.init(function() { alert(&#39;authenticated&#39;) }, function() { alert(&#39;auth failed&#39;) } );<br>
<br>
Addition methods:<br>
<br>
* login - redirect to login form<br>
* logout - log out<br>
* hasRealmRole(role) - returns true if user has the realm role<br>
* hasResourceRole(role, resource) - return true if user has the role for the specified resource (application)<br>
* loadUserProfile(success, failure) - loads the profile (in the future profile will be retrieved with IDToken from OpenID Connect spec, so this will probably not be required)<br>
* onValidAccessToken(success, failure) - invoke methods with a valid token. If the token is expired the refresh token is used to retrieve a new token before invoking the success callback<br>
<br>
Once authenticated the following properties are available as well:<br>
<br>
* token - base64 encoded token (use this as the value for the &#39;Authorization&#39; header, for example &quot;xMLHttpRequest.setRequestHeader(&#39;Authorization&#39;, &#39;Bearer &#39; + keycloak.token)&quot;)<br>
* tokenParsed - parsed token<br>
* authenticated - true if authenticated, false otherwise<br>
* subject - userId<br>
<br>
Please let me know how you get on with it, any feedback would be appreciated.<br>
<br>
Cheers,<br>
Stian<br>
<div><div class="h5"><br>
<br>
----- Original Message -----<br>
&gt; From: &quot;Rodrigo Del Canto&quot; &lt;<a href="mailto:delkant@gmail.com">delkant@gmail.com</a>&gt;<br>
&gt; To: <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; Sent: Saturday, 8 March, 2014 5:54:44 AM<br>
&gt; Subject: [keycloak-user] External JS AJAX client for jax-rs backend API<br>
&gt;<br>
&gt; Hello guys,<br>
&gt;<br>
&gt; Congrats on the release of project! I think this is the most useful project<br>
&gt; for developers in the whole history of internet :D<br>
&gt;<br>
&gt; I would like to know if you have any example on how to perform a login from<br>
&gt; an external JavaScript client?<br>
&gt;<br>
&gt; How would you recommend to do this. I heard you have a JS/jQuery lib to do<br>
&gt; this, where can it be found?<br>
&gt;<br>
&gt; Thanks,<br>
&gt;<br>
&gt; delkant<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; keycloak-user mailing list<br>
&gt; <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
</blockquote></div><br></div>