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 translation web resource #69

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

Conversation

austinmprince
Copy link

Updating the translation web resource to fetch the token for Translator resource instead of storing in plaintext javascript which could expose the customer to security risks

const oneMinuteInMs = 60 * oneSecondInMs;
const oneHourInMs = 60 * oneMinuteInMs;
const oneSecondInTicks = 10000000;
var Sdk = window.top.Sdk || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the name "window.top.Sdk" used anywhere else? Just thinking maybe we need to have a better/more specific name.

Copy link
Author

Choose a reason for hiding this comment

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

We are using window.top elsewhere, I have left this as is, let me know if you think it's better to use as a constant

return lanCode;
},
decodeToken: function(token) {
var base64Url = token.split('.')[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

null check and array length checking

},
decodeToken: function(token) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
Copy link
Contributor

Choose a reason for hiding this comment

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

null check

}
return ISO6391LanCode;
},
return JSON.parse(jsonPayload);
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add exception handling

"msdyn_isdisplayable": true,
"[email protected]": "/msdyn_ocliveworkitems(" + conversationId + ")"
};
autoRenewTranslationToken: function(token, timerIds) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add input parameters validations

return token;
}
catch (error){
console.log(error);
Copy link
Contributor

Choose a reason for hiding this comment

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

should be "console.error"

headers: {
"Content-Type": "application/json; charset=UTF-8",
"Authorization":
`Bearer ${C1WebResourceNamespace.authToken}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we support the secret approach at all? we should still keep the sample around, right?

Copy link
Author

Choose a reason for hiding this comment

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

Have added this as a separate file for implementation with translator v3 so we can keep the original sample around.

function () {
return {
initializeNewConversation:
C1WebResourceNamespace.initializeNewConversationInWebResource,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why breaking into new light?

boundParameter: null,
parameterTypes: {},
operationType: 1, // This is an action. Use '1' for functions and '2' for CRUD
operationName: "msdfm_GetTranslationToken",
Copy link
Contributor

Choose a reason for hiding this comment

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

seems this name should be more generic.

Copy link
Author

Choose a reason for hiding this comment

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

updated name to getTranslationToken

File contains implementation on Azure Translator v3 using Bearer Token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants