dimanche 11 mai 2014

CodeNameOne Google Plus OAuth2 - débordement de pile


Could anyone please help me with authenticating to Google Plus using OAuth2? I am able to get the authentication window to display, login and confirm my application with my account, but for some reason the action event is never fired. I get a screen saying Please copy this code, switch to your application and paste it there.


How do i get the action event to fire?


Thanks in advance.


Edit:


My code is as follows:


Hi Shai, thanks for the response, my code for the authentication is as follows:


Oauth2 auth2 = new Oauth2("https://accounts.google.com/o/oauth2/auth", "Client_Id", "urn:ietf:wg:oauth:2.0:oob or http://localhost", "openid", "https://accounts.google.com/o/oauth2/token", "Client_Secret");


Oauth2.setBackToParent(true);
auth2.showAuthentication(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof String) {
String token = (String) evt.getSource();
String expires = Oauth2.getExpires();
GOOGLE_TOKEN = token;
System.out.println("recived a token " + token + " which expires on " + expires);
//store token for future queries.
} else {
Exception err = (Exception) evt.getSource();
err.printStackTrace();
Dialog.show("Error", "An error occurred while logging in: " + err, "OK", null);
}
}
});

The "auth2.showAuthentication" works well, and allows you to pass through for the user to authorize the application but then once the user authorizes the application the "actionlistener" is never called, I never hit the callback. How can i force the callback to fire to return the token?



Could anyone please help me with authenticating to Google Plus using OAuth2? I am able to get the authentication window to display, login and confirm my application with my account, but for some reason the action event is never fired. I get a screen saying Please copy this code, switch to your application and paste it there.


How do i get the action event to fire?


Thanks in advance.


Edit:


My code is as follows:


Hi Shai, thanks for the response, my code for the authentication is as follows:


Oauth2 auth2 = new Oauth2("https://accounts.google.com/o/oauth2/auth", "Client_Id", "urn:ietf:wg:oauth:2.0:oob or http://localhost", "openid", "https://accounts.google.com/o/oauth2/token", "Client_Secret");


Oauth2.setBackToParent(true);
auth2.showAuthentication(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof String) {
String token = (String) evt.getSource();
String expires = Oauth2.getExpires();
GOOGLE_TOKEN = token;
System.out.println("recived a token " + token + " which expires on " + expires);
//store token for future queries.
} else {
Exception err = (Exception) evt.getSource();
err.printStackTrace();
Dialog.show("Error", "An error occurred while logging in: " + err, "OK", null);
}
}
});

The "auth2.showAuthentication" works well, and allows you to pass through for the user to authorize the application but then once the user authorizes the application the "actionlistener" is never called, I never hit the callback. How can i force the callback to fire to return the token?


0 commentaires:

Enregistrer un commentaire