Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.

Commit 4f8b706

Browse files
committed
Added convenience method to create challenge for Google Authenticator.
1 parent 499553e commit 4f8b706

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

api/src/main/java/com/stormpath/sdk/factor/google/GoogleAuthenticatorFactor.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,9 @@
2828
* <p/>
2929
* As such, the challenge can be created with the code at the same time:
3030
* <p/>
31+
*
3132
* <pre>
32-
* GoogleAuthenticatorChallenge challenge = client.instantiate(GoogleAuthenticatorChallenge.class);
33-
* challenge = (GoogleAuthenticatorChallenge) googleAuthenticatorFactor.createChallenge(
34-
* Challenges.GOOGLE_AUTHENTICATOR
35-
* .newCreateRequestFor(challenge)
36-
* <b>.withCode(code)</b>
37-
* .build()
38-
* );
33+
* GoogleAuthenticatorChallenge challenge = googleAuthenticatorFactor.createChallenge(code);
3934
* </pre>
4035
*
4136
* @since 1.1.0
@@ -93,4 +88,12 @@ public interface GoogleAuthenticatorFactor<T extends GoogleAuthenticatorChalleng
9388
* @return the base64QRImage.
9489
*/
9590
String getBase64QrImage();
91+
92+
/**
93+
*
94+
* @param code The code to validate the challenge that is created. With Google Authenticator, you can create a
95+
* challenge and validate it all in one call.
96+
* @return the {@link GoogleAuthenticatorChallenge}
97+
*/
98+
GoogleAuthenticatorChallenge createChallenge(String code);
9699
}

impl/src/main/java/com/stormpath/sdk/impl/factor/google/DefaultGoogleAuthenticatorFactor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.stormpath.sdk.challenge.google.GoogleAuthenticatorChallenge;
1919
import com.stormpath.sdk.factor.FactorType;
2020
import com.stormpath.sdk.factor.google.GoogleAuthenticatorFactor;
21+
import com.stormpath.sdk.impl.challenge.google.DefaultGoogleAuthenticatorChallenge;
2122
import com.stormpath.sdk.impl.ds.InternalDataStore;
2223
import com.stormpath.sdk.impl.factor.AbstractFactor;
2324
import com.stormpath.sdk.impl.resource.Property;
@@ -89,6 +90,13 @@ public String getBase64QrImage() {
8990
return getString(BASE64_QR_IMAGE);
9091
}
9192

93+
@Override
94+
public GoogleAuthenticatorChallenge createChallenge(String code) {
95+
GoogleAuthenticatorChallenge challenge = new DefaultGoogleAuthenticatorChallenge(getDataStore());
96+
challenge.setCode(code);
97+
return createChallenge(challenge);
98+
}
99+
92100
protected FactorType getConcreteFactorType() {
93101
return FactorType.GOOGLE_AUTHENTICATOR;
94102
}

0 commit comments

Comments
 (0)