-
Notifications
You must be signed in to change notification settings - Fork 4
[feature]Adding JSON structure with reference to Question api initial… #43
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
[feature]Adding JSON structure with reference to Question api initial… #43
Conversation
31242ff to
ba1d0ef
Compare
LearnositySDK/Request/Init.cs
Outdated
| this.validSecurityKeys = new string[5] { "consumer_key", "domain", "timestamp", "expires", "user_id" }; | ||
| this.validServices = new string[7] { "assess", "author", "data", "events", "items", "questions", "reports" }; | ||
| this.algorithm = "sha256"; | ||
| this.algorithm = "hmac256"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the algorithm name is hmac-sha256
LearnositySDK/Request/Init.cs
Outdated
| /// <param name="value"></param> | ||
| /// <returns>The hashed string</returns> | ||
| private string hashValue(string[] value) | ||
| private string hashValue(string prehash, string value ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the parameter "value" should be "secret" to make it more intuitive
| signatureList.Add(this.securityPacket.getString("user_id")); | ||
| signatureList.Add(this.secret); | ||
|
|
||
| string signature = this.hashValue(signatureList.ToArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the signatureList is only here, so maybe the declaration and the initialisation should be removed too?
LearnositySDK/Request/Init.cs
Outdated
| { | ||
| string user_id = users[i]; | ||
| hashedUsers.set(user_id, Tools.hash(this.algorithm, user_id + this.secret)); | ||
| hashedUsers.set(user_id, Tools.hash(this.algorithm,this.prehashString, user_id + this.secret)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need space after comma
LearnositySDK/Utils/CryptoUtil.cs
Outdated
| /// </summary> | ||
| /// <param name="s">String to be hashed</param> | ||
| /// <returns>64-character hex string</returns> | ||
| public static string hmac256(string prehash,string value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use a proper algorithm name, its hmac sha256
LearnositySDK/Utils/CryptoUtil.cs
Outdated
| /// </summary> | ||
| /// <param name="s">String to be hashed</param> | ||
| /// <returns>64-character hex string</returns> | ||
| public static string hmac256(string prehash,string value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the value should be secret
LearnositySDK/Utils/Tools.cs
Outdated
| /// <summary> | ||
| /// Returns HMAC256 hash | ||
| /// </summary> | ||
| /// <param name="prehash"></param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need explanation of the parameters
LearnositySDK/Utils/Tools.cs
Outdated
| /// <param name="value"></param> | ||
| /// <returns></returns> | ||
| public static string hash(string algorithm, string message) | ||
| public static string hash(string algorithm, string prehash, string value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value
| this.validSecurityKeys = new string[5] { "consumer_key", "domain", "timestamp", "expires", "user_id" }; | ||
| this.validServices = new string[7] { "assess", "author", "data", "events", "items", "questions", "reports" }; | ||
| this.algorithm = "hmac256"; | ||
| this.algorithm = "hmac-sha256"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed name to hmac-sha256
| private string hashValue(string prehash, string secret ) | ||
| { | ||
| string hash = Tools.hash(this.algorithm, prehash, value); | ||
| string hash = Tools.hash(this.algorithm, prehash, secret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added summary for params , changed params name to secret as per the comments given
LearnositySDK/Request/Init.cs
Outdated
|
|
||
| signatureList.Add(this.securityPacket.getString("user_id")); | ||
| signatureList.Add(this.secret); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove extra lines in my next commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
|
|
||
| signatureList.Add(this.securityPacket.getString("user_id")); | ||
| signatureList.Add(this.secret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the review signatureList initialisation and declaration has been removed
| { | ||
| string user_id = users[i]; | ||
| hashedUsers.set(user_id, Tools.hash(this.algorithm,this.prehashString, user_id + this.secret)); | ||
| hashedUsers.set(user_id, Tools.hash(this.algorithm, this.prehashString, user_id + this.secret)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added space after comma
| ///<param name="secret">String used for encryption</param> | ||
| /// <returns>64-character hex string</returns> | ||
| public static string hmac256(string prehash,string value) | ||
| public static string hmacsha256(string prehash, string secret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed algo to hmacsha256
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed param value to secret and also added function summary with params
| /// <param name="prehash"></param> | ||
| ///<param name="value"></param> | ||
| /// <param name="prehash">String to be hashed</param> | ||
| ///<param name="secret">String used for encryption</param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added comments for params
| /// <param name="secret">String used for encryption</param> | ||
| /// <returns></returns> | ||
| public static string hash(string algorithm, string prehash, string value) | ||
| public static string hash(string algorithm, string prehash, string secret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed value to secret(params)
| { | ||
| case "hmac256": | ||
| str = Tools.hmac256(prehash, value); | ||
| case "hmac-sha256": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed name to hmac-sha256
82ef665 to
a82f88c
Compare
| // item_edit mode and item_list mode | ||
| // the below example generate initOptions for item_edit mode | ||
| // more information about item_list mode can be found in initializeItemList() function | ||
| Init init = (mode == "item_list") ? initializeItemEdit() : initializeItemList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this conditional correct? if mode is item_list, then you will return itemEdit, and if mode is not item_list then you return item_list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh I need to correct that , If mode is Item list it should return itemList not item edit. Thanks For pointing it out I will make that change
| // the below example generate initOptions for item_edit mode | ||
| // more information about item_list mode can be found in initializeItemList() function | ||
| Init init = (mode == "item_list") ? initializeItemEdit() : initializeItemList(); | ||
| Init init = (mode == "item_list") ? initializeItemList() : initializeItemEdit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just need to remove unnecessary space after '?'
0e63b85 to
79fdbd6
Compare
bc57763 to
083e761
Compare
af9ba81 to
019801f
Compare
TheRealEdDawson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some minor comments, but generally, looks great, guys. Please go ahead!
TheRealEdDawson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Thanks @bhavya-shukla-lrn , please go ahead with it.
d10e1e2 to
9abab5a
Compare
TheRealEdDawson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @bhavya-shukla-lrn @markus-liang-lrn @markkellyeire, I made some minor edits to text in "README.md" and to the copyright year in "LearnositySDK.csproj", to change it to this year "2023".
abe9b6b to
04f6de5
Compare
…ages for the new signature LRN-38572 Change in branch
04f6de5 to
a6bf743
Compare
…ization object[LRN-38974]