Secure Storage in Stackview

385
8
Jump to solution
11-13-2018 10:18 AM
GiatriLalla
New Contributor III

Good Day,

How can I retrieve a value and/ a key on Page 1 for instance, if it was stored using secure storage on the Startpage of a stackview layout. I have tried the value method however I am not successful. For example: 

1. Start Page would look something like

TextField {

   id: key

   placeholderText: "Enter key"

}

TextField {

   id:value

   placeholderText: "Enter value"

   anchors.left: key.right

}

//Click on the button to store data into keychain 

Button {

   id: SecureButton

   text: qsTr ("Secure Data")

   anchors.left: key.bottom

   onClicked: {

         SecureStorage.setValue(key.text, value.text)

}

}

2. Page 1 would look something like

//Click on button to retrieve data

Button {

   id: retrieveButton

   text: qsTr ("Retrieve Data")

   anchors.top: secureButton.bottom

   onClicked: {

         retrieveData.text = qsTr("Value:") + SecureStorage.value(key.text)

}

}

//Display retrieved data

Text {

   id:retrieveData

   anchors.top: retrieveButoon.bottom

The information is being stored however I can not retrieve the information.

0 Kudos
1 Solution

Accepted Solutions
JaysonWard
New Contributor III

I think the issue is that the key and value components with their associated properties aren't available to the Page 1 view in the stack since they are defined in Start Page and aren't global or passed to Page 1.

View solution in original post

8 Replies
ErwinSoekianto
Esri Regular Contributor

Giatri, 

That should work, what is the error message? Did you make sure to have the import statement in the other page?

Please refer to this documentation page for Secure Storage and sample page

Thank you,

Erwin. 

0 Kudos
JaysonWard
New Contributor III

I think the issue is that the key and value components with their associated properties aren't available to the Page 1 view in the stack since they are defined in Start Page and aren't global or passed to Page 1.

GiatriLalla
New Contributor III

Good Morning,

How can I rectify this? Thank you.

0 Kudos
JaysonWard
New Contributor III

Hi Giatri:

I'm not sure if there are security implications to these but you would need to either:

  1. Create a string property on the App component and assign the key.value to it at the same time you set the SecureStorage.value. Then you can reference that 'global' string property in Page 1, or
  2. Create a string property on each view, assign the key.value to the property in StartPage, then when you push Page1 onto the stack, assign the string property in Page 1 to the string property value on Start Page

So Number 1 above would look something like this:

App {
id: app
width: 400
height: 750

property string secureStorageKeyValue: ""

.....

//Click on the button to store data into keychain 

Button {

   id: SecureButton

   text: qsTr ("Secure Data")

   anchors.left: key.bottom

   onClicked: {

         app.secureStorageKeyValue = key.text;

         SecureStorage.setValue(key.text, value.text);

}

Page 1

Button {

   id: retrieveButton

   text: qsTr ("Retrieve Data")

   anchors.top: secureButton.bottom

   onClicked: {

         retrieveData.text = qsTr("Value:") + SecureStorage.value(app.secureStorageKeyValue);

}

}

Number 2

StartPage {

   id: startPage

   property string secureStorageKeyValue: ""

//Click on the button to store data into keychain 

Button {

   id: SecureButton

   text: qsTr ("Secure Data")

   anchors.left: key.bottom

   onClicked: {

         startPage.secureStorageKeyValue = key.text;

         SecureStorage.setValue(key.text, value.text);

}

 

yourStackView.push( pageOneViewId, { "secureStorageKeyValue": startPage.secureStorageKeyValue } );

}

PageOne {

 id: pageOne

property string secureStorageKeyValue: ""

Button {

   id: retrieveButton

   text: qsTr ("Retrieve Data")

   anchors.top: secureButton.bottom

   onClicked: {

         retrieveData.text = qsTr("Value:") + SecureStorage.value(secureStorageKeyValue);

}

}

GiatriLalla
New Contributor III

I had a chance to try both. I don't think any work for me. The second option gave alot of errors and the first is giving me the results as seen in the picture. I dont not know how to proceed. For privacy reasons, I do not want to share my code on here but if I can get that to you, maybe you'd be able to see the results yourself. Please advise accordingly. Thank you in advance.

0 Kudos
ErwinSoekianto
Esri Regular Contributor

I would recommend working with Esri Technical Support‌ for further troubleshooting. 

0 Kudos
GiatriLalla
New Contributor III

I do not get any response from Esri Technical Support when I post a question.

0 Kudos
ErwinSoekianto
Esri Regular Contributor

Our apologies, what I was trying to say is, you should contact Esri Technical Support, Esri Support Contact Support , via phone call, email or chat. 

0 Kudos