Hello Marek,
What is the value of onLoad during keycloak init() function?
I tried both check-sso and login-required, but it still is showing the kc login page.
Heres what I did.
Using java code I get a direct access grant tokens. I get response from this code as something below.
{"access_token":"eyJhbGciOiJSUzI1NiJ9blahblah","expires_in":1800,"refresh_expires_in":1800,"refresh_token":"eyJhbGciOiblahblah","token_type":"bearer","id_token":"eyJhbGciblah blah","not-before-policy":1437991554,"session-state":"7afb2db2-6f4f-43a8-a9ad-355d5cc5c8fe"}
Then I am hitting the jsp page.
http://localhost:8080/myapp/index.jsp?tokenJson=<theabovejsonstring-cut-and-pasted>
In index.jsp I extract the tokenJson param and parse the json to further extract the accessToken, idToken and refreshToken.
A code snippet in index.jsp, like the below generates the keycloak init obj.
<%
String iaJsonStr =request.getParameter("tokenJson");//get the token json from url
String token="",idToken="",refreshToken="";//init the values
if(!StringUtils.isEmpty(iaJsonStr)){
JsonObject iaJsonObj = Json.createReader(new StringReader(iaJsonStr)).readObject();
token=iaJsonObj.getString("access_token");//extract access
refreshToken=iaJsonObj.getString("refresh_token");//extract refresh
idToken=iaJsonObj.getString("id_token");//extract id
}
if(!StringUtils.isEmpty(token) && !StringUtils.isEmpty(refreshToken) && !StringUtils.isEmpty(idToken)){
%>
var kcInitObj={
onLoad:'check-sso',
token:'<%=token%>',
refreshToken:'<%=refreshToken%>',
idToken:'<%=idToken%>'
};
<%
}else{
%>
var kcInitObj={
onLoad:'check-sso'
};
<%
}
%>
.......
.....
<script>
var keycloak = Keycloak('/myapp/keycloak-dev.json');
keycloak.init(kcInitObj).success(function(authenticated) {
if(!authenticated){
keycloak.login();
}else{
//call loadProfile and get the user details.
).error(....)
</script>
This is still redirecting me to the login page. Do I have to do something in the client setup?
So close,, yet so far... Please help..
Thanks and lot for your attention.
Subhro.