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

Conversation

@dogeared
Copy link
Member

Resolves #1243

@dogeared dogeared added this to the 1.4.0 milestone Jan 17, 2017
@dogeared
Copy link
Member Author

dogeared commented Jan 17, 2017

This enables creating a challenge including the code at the same time for GoogleAuthenticator:

        GoogleAuthenticatorChallenge challenge = client.instantiate(GoogleAuthenticatorChallenge.class);
        challenge = (GoogleAuthenticatorChallenge) factor.createChallenge(
            Challenges.GOOGLE_AUTHENTICATOR
                .newCreateRequestFor(challenge)
                .withCode(code)
                .build()
        );

NOTE: I will add the above to the javadocs before deploying. Just wanted to get it built on CI first.

setProperty(CODE, code);
return this;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we remove the setCode() method and made the property public instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, that method was only used in one place in the validate method, and in two places in tests which should not have had access to that protected method anyway. So there was no need for it.
The property, on the other hand, is used both in the validate method and now also when creating a Google Authenticator challenge and providing the code at the same time (which is not allowed in the SMS case).

@Override
public void setCode(String code) {
setProperty(CODE, code);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method could have stayed in the Abstract Class, no? SmsChallenge also needs to be able to set the code.
Looking at the following snippet in IAM for SmsChallenge
JsonPath challengeResponse = postRestCall(challenge.href + "?expand=factor", [code: code])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above. There is no reason for a code to be set on an SMS challenge outside of the validate method.

Copy link
Contributor

@mrafiei mrafiei Jan 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But doesn't the snippet above post to the sms challenge with a code in the body? That means it is supported on the API.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrafiei - Previously, the interface didn't support calling setCode for either SMS or GA as it was not public. Based on the way that GA works, it makes sense to set the code at the same time you create the challenge. It doesn't make the same sense for SMS, which is why we moved it into the more specific GA side of things.

What I am saying is that with GA, you can algorithmically know the code, which is how the TOTP app gives it to you, so it makes sense to be able to create the challenge and submit the code all in one shot.

With SMS, you can't know the code (from an end-user perspective) until you've received the text. I will dig into the spec in Jira/Confluence some more, but am I missing something here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrafiei POSTing to a challenge href with a code is indeed supported by the REST API, and that is what is mirrored by the validate method on AbstractChallenge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dogeared Its correct what you stated above, my only thing is since it is supported on the REST API we should also support it for Sms challenges on SDK side to be consistent.

@@ -0,0 +1,5 @@
package com.stormpath.sdk.challenge.google;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license header

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed.


import com.stormpath.sdk.challenge.CreateChallengeRequest;

public interface GoogleAuthenticatorCreateChallengeRequest extends CreateChallengeRequest {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Javadoc. In particular both a short description and the version are important since it is an interface in the api module

@@ -0,0 +1,8 @@
package com.stormpath.sdk.challenge.google;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed


import com.stormpath.sdk.challenge.CreateChallengeRequestBuilder;

public interface GoogleAuthenticatorCreateChallengeRequestBuilder extends CreateChallengeRequestBuilder<GoogleAuthenticatorChallenge> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Javadoc in the class and in the method. Both a short description and the version are important since it is an interface in the api module

@@ -0,0 +1,13 @@
package com.stormpath.sdk.impl.challenge.google;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@@ -0,0 +1,24 @@
package com.stormpath.sdk.impl.challenge.google;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing license

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adressed

@mrioan
Copy link
Contributor

mrioan commented Jan 18, 2017

@dogeared now that I see that a developer would do:

GoogleAuthenticatorChallenge challenge = client.instantiate(GoogleAuthenticatorChallenge.class);
        challenge = (GoogleAuthenticatorChallenge) factor.createChallenge(
            Challenges.GOOGLE_AUTHENTICATOR
                .newCreateRequestFor(challenge)
                .withCode(code)
                .build()
        );

I does not look good to me. You are creating a challenge and then creating another one passing that challenge. I think the proper sentence should be like this:

GoogleAuthenticatorChallenge challenge = (GoogleAuthenticatorChallenge) factor.createChallenge(
            Challenges.GOOGLE_AUTHENTICATOR
                .withCode(code)
                .build()
        );

See that the operation createChallenge already knows that it will create a challenge and it is receiving a google code as a parameter.

@dogeared
Copy link
Member Author

@mrioan - I agree. However, this pattern is all throughout MFA code and will require some more refactoring to have the change be more systemic. I will endeavor to update the code you pointed out as the model for other changes and I'll put in issues for those other changes in upcoming releases.

Copy link
Contributor

@mrioan mrioan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dogeared Two minor comments. When they are addressed you can consider this PR approved

*
* @since 1.4.0
*/
public interface GoogleAuthenticatorCreateChallengeRequestBuilder extends CreateChallengeRequestBuilder<GoogleAuthenticatorChallenge> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this class still needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrioan - I think so. There are two supported ways to validate a challenge on the backend - by hitting the .../factors... collection endpoint and by hitting a specific challenge endpoint, so I think we need to support that in the SDK as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but, maybe not - looking

* challenge and validate it all in one call.
* @return the {@link GoogleAuthenticatorChallenge}
*/
GoogleAuthenticatorChallenge createChallenge(String code);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dogeared dogeared merged commit a239274 into master Jan 18, 2017
@dogeared dogeared deleted the GA_Refactor branch January 18, 2017 17:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants