<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">In that case, I would likely invoke the
redirection to some suffixed URL when user click to your "Login"
button. And the call to the keycloak.init() will be done only when
URL ends with this suffix (or you can use the query parameter). <br>
<br>
For example in the onClick event called when your button is
clicked you will have:<br>
<br>
var myLoginCallback = function() {<br>
if (auth.loggedIn) {<br>
// User is already logged in. Don't do anything or do
whatever you want based on your app logic<br>
} else {<br>
// Redirect to the suffixed URL<br>
window.location = '/myapp/login';<br>
}<br>
}<br>
<br>
The angular bootstrap can then look like this:<br>
<br>
angular.element(document).ready(function ($http) {<br>
var keycloakAuth = new Keycloak('keycloak.json');<br>
auth.loggedIn = false;<br>
<br>
if (window.location.endsWith('/myapp/login')) {<br>
keycloakAuth.init({ onLoad: 'login-required'
}).success(function () <br>
/// ... Use the code like in the example app <br>
} else {<br>
// Automatically bootstrap angular. Application would be
in anonymous mode<br>
angular.bootstrap(document, ["product"]);<br>
} <br>
});<br>
<br>
Marek<br>
<br>
On 29.7.2015 14:39, Fabio Monteiro wrote:<br>
</div>
<blockquote cite="mid:DUB131-W828F0D718D2801786BBCEBD58C0@phx.gbl"
type="cite">
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style>
<div dir="ltr">Hi ,
<div><br>
</div>
<div>I'm looking for a simple way to login to keycloak with an
AngularJS app. </div>
<div>If i use the example (angular-produt-app) one can find with
the keyCloak appliance, the js adapter redirects the user to
the Keycloak login pase "onload " (<span style="font-family:
'Courier New'; font-size: 7.2pt; color: rgb(69, 131, 131);">keycloakVar</span><span
style="font-family: 'Courier New'; font-size: 7.2pt;">.</span><span
style="font-family: 'Courier New'; font-size: 7.2pt; color:
rgb(122, 122, 67);">init</span><span style="font-family:
'Courier New'; font-size: 7.2pt;">({</span><span
style="font-family: 'Courier New'; font-size: 7.2pt; color:
rgb(102, 14, 122); font-weight: bold;">onLoad</span><span
style="font-family: 'Courier New'; font-size: 7.2pt;">: </span><span
style="font-family: 'Courier New'; font-size: 7.2pt; color:
rgb(0, 128, 0); font-weight: bold;">'login-required'</span><span
style="font-family: 'Courier New'; font-size: 7.2pt;">})...</span><span
style="font-size: 12pt;">) </span></div>
<div><br>
</div>
<div>But i want to login only when I specifically click on some
button. F<span style="font-size: 12pt;">rom what I can gather</span><span
style="font-size: 12pt;"> </span><span style="font-size:
12pt;">the method </span><span style="color: rgb(69, 131,
131); font-family: 'Courier New'; font-size:
9.60000038146973px;">keycloakVar.login() </span></div>
<div>from the docs & JS reference is the way to go.. but
replacing the .init() method with the .login() method doesn't
seem to work...</div>
<div><br>
</div>
<div>Also, in the "normal" case, the init() regular example
itself lets me, after logging-in succesfully, with still empty
Javasript objects once I am successfully redirected to my app
page. (the auth global variable)</div>
<div><br>
</div>
<div><br>
</div>
<div>The official angular + js-adapter : <a
moz-do-not-send="true"
href="https://github.com/keycloak/keycloak/blob/master/examples/demo-template/angular-product-app/src/main/webapp/js/app.js"
target="_blank" style="font-size: 12pt;">https://github.com/keycloak/keycloak/blob/master/examples/demo-template/angular-product-app/src/main/webapp/js/app.js</a></div>
<div><br>
</div>
<div><br>
</div>
<div>Could you help me ? I must be missing something.</div>
<div><br>
</div>
<div><br>
Thanks a lot</div>
<div><br>
<font face="Franklin Gothic Medium">Fabio M</font></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>