Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update flex examples #38

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

Update flex examples #38

wants to merge 20 commits into from

Conversation

bprokopc
Copy link
Collaborator

Add Flex direct live demo + source code.
Deploy microform demo to Google Cloud and make live demo available.
Upgrade microform demo to SpringBoot 3 / Java 17.

3. ```FlexApiHeaderAuthenticator.java``` complete HTTP Signature authentication implementation that can be plugged to any JAX-RS client implementation as an ```@Provider```.
4. ```FlexApiPublicKeysResolver.java``` complete cryptographic Key provider for Jose4J that can retrieve and cache Flex API long living keys.

# Deployment to Google Cloud

Choose a reason for hiding this comment

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

Should this be h2?


For details, please consult https://quarkus.io/guides/maven-tooling#dev-mode.

## Few technical details

Choose a reason for hiding this comment

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

Could remove the word "Few" and just have "Technical details"?

</dependencies>
</dependencyManagement>

<dependencies>

Choose a reason for hiding this comment

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

Just a note that not all of these are available on the CYBS maven mirror, unless you have a different one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll answer this internally.


Flex Direct API allows merchants to write their own integration based on Transient Token concept.
For example Flex API can be used to isolate systems that capture *payment credentials* from systems that invoke *card services*.
Flex API facilitates keeping *payment credentials* away from merchant's backend processing, keeping those systems away from PCI compliance.

Choose a reason for hiding this comment

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

"reducing PCI scope." may be more accurate?


private JsonObject payload(String jwt) {
// nasty way - do not do this at home
jwt = jwt.substring(jwt.indexOf('.') + 1);

Choose a reason for hiding this comment

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

Should we give this a more readable name since we're just trying to isolate the payload?

Still gross but might be slightly cleaner to do something like

final String[] jwtChunks = jwt.split("\\.");
return new JsonObject(Base64.getDecoder().decode(jwtChunks[1]));

?

*/
private static final String HMAC_ALG = "HmacSHA256";

private static String getDigest(String payload) {

Choose a reason for hiding this comment

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

There's nothing in the rest-client to do the heavy lifting here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is unlikely that merchant with the need for Flex Direct will require SDK. Flex Direct is a low level API contract for advanced and custom integrations, including merchant responsibility for JWE encryption - i.e. no reliance on microform or any other SDK. So Let's then for consistency have same approach for API calls.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is an authentication SDK that does this for you. It is not the full SDK of the APIs but it is much better than coding this again.

@bprokopc Maybe consider that SDK instead.

<configuration>
<projectId>flex-mf-springboot-sample</projectId>
<version>3</version>
<!-- <artifact>${project.build.directory}/xxxx.jar</artifact>-->

Choose a reason for hiding this comment

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

Is this something users would ever want to uncomment?

final long lineCount = lines.count();
model.addAttribute("requestLineCount", lineCount);
}
model.addAttribute("requestLineCount", new String(captureContextRequestJson.getInputStream().readAllBytes(), "UTF-8"));

Choose a reason for hiding this comment

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

This is supposed to be a numerical value. Since we're reading bytes is it possible anymore to set this easily? If not should be safely removable

#app.merchantID=
#app.merchantKeyId=
#app.merchantSecretKey=
app.merchantID=

Choose a reason for hiding this comment

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

I'd leave the commented. We want to encourage users to set these in application-local.properties which can't be checked in without modifying the .gitignore.

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
Copy link
Contributor

@gnongsie gnongsie Aug 21, 2023

Choose a reason for hiding this comment

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

Why was this downgraded? Please note that the prerequisite mentioned in the README.md file is Java 14.

}
String[] split = key.split("\\.");

for (int i = 0; i < split.length; i++) {

Choose a reason for hiding this comment

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

I find this pretty unreadable. Is this functionally equivalent?

        Arrays.stream(key.split("\\.")).forEach( s -> {
            if (!fields.containsKey(s)) {
                fields.put(s, new JsonObject());
            }
        });


@Provider
@ConstrainedTo(RuntimeType.CLIENT)
public class FlexApiHeaderAuthenticator implements WriterInterceptor {

Choose a reason for hiding this comment

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

Do we need this class at all? Can't we just use Cybersource provided ApiClient and make a generic Call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants