Skip to content

Commit

Permalink
add way to retrieve refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
ramabit committed Jul 12, 2016
1 parent fd41734 commit 6c25068
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
private final Map<String, IQRequestHandler> setIqRequestHandler = new HashMap<>();
private final Map<String, IQRequestHandler> getIqRequestHandler = new HashMap<>();

/**
* Indicates the last refresh token received via the X-OAUTH mechanism.
*/
protected String refreshTokenXOAUTH;

/**
* Create a new XMPPConnection to an XMPP server.
*
Expand Down Expand Up @@ -593,15 +598,34 @@ protected void afterSuccessfulLogin(final boolean resumed) throws NotConnectedEx
}
}

/**
* Get the X-OAUTH last refresh token.
*
* @return the X-OAUTH last refresh token
*/
@Override
public String getXOAUTHLastRefreshToken() {
return refreshTokenXOAUTH;
}

/**
* Set the X-OAUTH last refresh token.
*/
@Override
public void setXOAUTHLastRefreshToken(String token) {
refreshTokenXOAUTH = token;
}

@Override
public final boolean isAnonymous() {
return isAuthenticated() && SASLAnonymous.NAME.equals(getUsedSaslMechansism());
}

/**
* Get the name of the SASL mechanism that was used to authenticate this connection. This returns the name of
* mechanism which was used the last time this conneciton was authenticated, and will return <code>null</code> if
* this connection was not authenticated before.
* Get the name of the SASL mechanism that was used to authenticate this
* connection. This returns the name of mechanism which was used the last
* time this connection was authenticated, and will return <code>null</code>
* if this connection was not authenticated before.
*
* @return the name of the used SASL mechanism.
* @since 4.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import org.jivesoftware.smack.filter.IQReplyFilter;
import org.jivesoftware.smack.filter.StanzaFilter;
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Nonza;
import org.jivesoftware.smack.packet.Stanza;
import org.jxmpp.jid.DomainBareJid;
import org.jxmpp.jid.EntityFullJid;

Expand Down Expand Up @@ -625,4 +625,18 @@ public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callba
*/
public long getLastStanzaReceived();

/**
* Set the X-OAUTH last refresh token.
*
* @param token
*/
public void setXOAUTHLastRefreshToken(String token);

/**
* Get the X-OAUTH last refresh token.
*
* @return the X-OAUTH last refresh token
*/
public String getXOAUTHLastRefreshToken();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.sasl.SASLMechanism;
import org.jivesoftware.smack.util.stringencoder.Base64;

public class SASLXOAUTHMechanism extends SASLMechanism {

Expand Down Expand Up @@ -59,4 +60,12 @@ protected byte[] getAuthenticationText() throws SmackException {
public void checkIfSuccessfulOrThrow() throws SmackException {
// No check performed
}

@Override
protected byte[] evaluateChallenge(byte[] challenge) throws SmackException {
String refreshToken = Base64.encodeToString(challenge);
connection.setXOAUTHLastRefreshToken(refreshToken);
return null;
}

}

0 comments on commit 6c25068

Please sign in to comment.