Skip to content
New issue

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

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

Already on GitHub? # to your account

HTTP header support #153

Merged
merged 4 commits into from
Jan 9, 2019
Merged

HTTP header support #153

merged 4 commits into from
Jan 9, 2019

Conversation

smelzer
Copy link
Contributor

@smelzer smelzer commented Jan 2, 2019

Roman,
I have add HTTP header support for iOS and Android. I tried to modify as little as possible and it is non-contract breaking. I added a new option called "headers" that takes a JSON string of header key/value pairs. For example in my tests with a JWT token for authorization using your example:

var options = {
    share: true, // default is false
    closeButton: false, // default is true
    copyToReference: true // default is false
    headers: '{"Authorization":"Bearer eyJ0eXAiOiJKV1QiLC..."}' // default is no headers
};

PhotoViewer.show('http://my_authenticated_site.com/my_image.jpg', 'Optional Title', options);

BUT, and this is a big but, I have no idea how to actually test this in a Cordova environment.

Instead, for iOS I created a small single-page-view iOS sample app and had the ViewController use the PhotoViewer.m file the same way I believe Cordova is using it. The code was very straight-forward:

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    PhotoViewer *photoViewer = [PhotoViewer alloc];
    NSString *title = @"TITLE";
    NSString *urlString = [NSString stringWithFormat:@"http://localhost:8080/service/v1/documents/%d/page/%d/show", 580, 1];
    NSString *token = @"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzUxMiJ9.eyJpc3MiOiJhdXRoMCIsIm5hbWUiOiJCdWdzIEJ1bm55IiwiZXhwaXJlQXRFcG9jaE1pbGxpcyI6MTU0NjM5NzE2MzUwNiwicHJvZ3JhbXMiOls1Ml0sInVzZXJUeXBlIjoxLCJpZCI6NjksImV4cCI6MTU0NjM5NzE2M30.rlXiBSvnl3WZOq2vpvnBNWYZKupJU78d1h7EZpXscbJBbueV3rJjML4H00fggHiLejnxEqyj7QLCtOf3dmlYiW3cVjxS_jsvkHlqeM8QM95jR4EatDtVV3bQXflq_QE_y2fL8A-kDxyz3IEbEHMYzn9tO-bdWhbN_QvimoSMuMbH9ogRmZkjxp5ru5avwxCMfi_nngi7bZgyLSm7FtQtfHLzI4jB4fq0z2ForsAI3KWJIYDi2Kq2fGYVi9x_0TKtFvQzWpA-JIAGTtN_jbNlOM8vPF7oCf9_sSSI9wb702tcwf1d-zfOraCLQXsrp4QEYd5JY6rIU8u401FvEVnnrg";
    NSString *headerString = [NSString stringWithFormat:@"{\"Authorization\":\"Bearer %@\"}", token];
    NSArray *parameters = [NSArray arrayWithObjects:urlString, title, @"false", @"false", @"false", headerString, nil];
    photoViewer.viewController = self;
    [photoViewer show:parameters];
}

@end

And for Android I created a single Activity app where the MainActivity calls the PhotoActivity.java:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        JSONArray args = new JSONArray();
        String token = "eyJ0eXAiOiJKV1QiLC...";
        args.put("http://api.documentsentry.com/service/v1/documents/580/page/1/show");
        args.put("TITLE");
        args.put("true");
        args.put("true");
        args.put("true");
        args.put("{\"Authorization\":\"Bearer " + token + "\"}");

        Intent i = new Intent(this, com.example.smelzer.photoviewertestharness.PhotoActivity.class);
        PhotoActivity.mArgs = args;

        this.startActivity(i);
    }

I tried many variations of the parameters with both insecure and secure URLs and different options (I removed all the combinations from the sample above for readability). Everything appears to work as expected, at least from my test harnesses. If you want me to test further from Cordova I will need some help understanding how to actually do it.

Let me know what you think.

Thanks,
Steve

@smelzer smelzer changed the title HTTP header support (iOS only) HTTP header support Jan 4, 2019
@sarriaroman sarriaroman merged commit ed71cfe into sarriaroman:master Jan 9, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants