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

provideEmbeddedHeaders not working in <img> tag #533

Closed
9 of 15 tasks
AnuDharmarajan opened this issue Nov 3, 2021 · 11 comments
Closed
9 of 15 tasks

provideEmbeddedHeaders not working in <img> tag #533

AnuDharmarajan opened this issue Nov 3, 2021 · 11 comments
Labels
bug Crush'em all.

Comments

@AnuDharmarajan
Copy link

Decision Table

  • My issue does not look like “The HTML attribute 'xxx' is ignored” (unless we claim support for it)
  • My issue does not look like “The HTML element <yyy> is not rendered”

Good Faith Declaration

Description

I have added Authorization in img tag it is not working.

React Native Information

"react-native": "0.64.1",

RNRH Version

I am using react-native-render-html Version 6.1.0

Tested Platforms

  • Android
  • iOS
  • Web
  • MacOS
  • Windows

Reproduction Platforms

  • Android
  • iOS
  • Web
  • MacOS
  • Windows

Minimal, Reproducible Example

function provideEmbeddedHeaders(uri, tagName) {

if (tagName === "img" && uri.startsWith("https://xxx.xxx.com")) {

  return {
    
    Authorization: 'Bearer ' + accessToken
   
  }
}

}
return( <RenderHtml
contentWidth={Dimensions.get('window').width - wp('10%')}
source={{html: '<img src="https://xxxx.xxx.xx/xxxx/xx/xxxx/xxx/xxxx/23553.png"'}}
scrollEnabled={false}
//enableCSSInlineProcessing={true}
baseStyle={{fontSize:normalize(13)}}
emSize = {normalize(13)}
renderersProps={renderersProps}
provideEmbeddedHeaders={provideEmbeddedHeaders}
enableCSSInlineProcessing={true}
//absoluteFontSizesPixelMap ={'large'}
/>
)

Additional Notes

No response

@AnuDharmarajan AnuDharmarajan added the bug Crush'em all. label Nov 3, 2021
@jsamr
Copy link
Collaborator

jsamr commented Nov 3, 2021

Hi @AnuDharmarajan, and thanks for your contribution! You didn't explain how you came up to the conclusion that the headers were not passed? Do you have access to the server logs? I'll be happy to help when you provide additional information. Thanks!

@AnuDharmarajan
Copy link
Author

@jsamr Thank you for your quick replay. I don't have access in the server. The image is in the share point and we are passing the share point token for Authorization.

@jsamr
Copy link
Collaborator

jsamr commented Nov 3, 2021

@AnuDharmarajan Did you manage authentication successfully by other means, with postman or other HTTP utilities, so that you can assert this library is faulty? The provideEmbeddedHeaders prop is unit-tested, I have doubts the issue is with this library:

describe('regarding provideEmbeddedHeaders prop', () => {
it('should apply returned headers to IMG tags', async () => {
const headers = {
Authorization: 'Bearer XXX'
};
function provideEmbeddedHeaders(uri: string, tag: string) {
expect(tag).toBe('img');
return headers;
}
const { UNSAFE_getByType, findByTestId } = render(
<RenderHTML
source={{
html: '<img src="https://custom.domain/" />'
}}
debug={false}
contentWidth={100}
provideEmbeddedHeaders={provideEmbeddedHeaders}
/>
);
await findByTestId('image-success');
const image = UNSAFE_getByType(Image);
expect(image.props.source.headers).toBe(headers);
});
});

@AnuDharmarajan
Copy link
Author

I have managed the authentication successfully in the postman and Image view also. It works fine.But in the Renderhtml it is not working.

@jsamr
Copy link
Collaborator

jsamr commented Nov 3, 2021

@AnuDharmarajan Can you log in the console from the first line of your provideEmbeddedHttpHeaders and test if this log is being called, and if it is, with which arguments? In the snippet you provided, the HTML string is not valid HTML.

@AnuDharmarajan
Copy link
Author

AnuDharmarajan commented Nov 3, 2021

The console is called when there is a img tag. I have given a sample HTML in the snippet because I am not able to provide the correct URL in the public platform.

@jsamr
Copy link
Collaborator

jsamr commented Nov 3, 2021

@AnuDharmarajan I am reviewing the code; will let you know.

@jsamr
Copy link
Collaborator

jsamr commented Nov 3, 2021

@AnuDharmarajan It looks like the header is set after fetching the natural dimensions of the image, which would result in an error. I will provide a patch soon!

@AnuDharmarajan
Copy link
Author

@jsamr Thank you.

jsamr added a commit that referenced this issue Nov 3, 2021
@jsamr jsamr closed this as completed in 5488259 Nov 3, 2021
@jsamr
Copy link
Collaborator

jsamr commented Nov 3, 2021

@AnuDharmarajan Should be fixed in v6.3.0, let me know!

@subspacefield-or
Copy link

I'm using version 6.3.4 in IOS and this still seems to be an issue. I have an html fragment like follows: Logo and this requires a bearer token to access. I add provideEmbeddedHeaders as follows:

    function provideEmbeddedHeaders(uri, tagName, params) {
        console.log("provideEmbeddedHeaders: %s", uri);
        if (tagName === "img" && uri.includes("?????")) {
            const bearerString = `Bearer ${AuthConfig.getAuthToken()}`;
            return {
                Authorization: bearerString
              }
        }
    }
    <RenderHtml
        contentWidth={width}
        source={source}
        enableExperimentalBRCollapsing={true}
        provideEmbeddedHeaders={provideEmbeddedHeaders}
        debug={true}
        renderersProps={renderersProps}
    />                                

I verified using Postman that the image can be downloaded with the token. Let me know if there are anymore details that can be provided to track down this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Crush'em all.
Projects
None yet
Development

No branches or pull requests

3 participants