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

SOLIDPOD: Implement SolidLoginPopup() for bstim #3

Closed
2 tasks
gjwgit opened this issue Dec 18, 2023 · 15 comments
Closed
2 tasks

SOLIDPOD: Implement SolidLoginPopup() for bstim #3

gjwgit opened this issue Dec 18, 2023 · 15 comments
Assignees

Comments

@gjwgit
Copy link
Contributor

gjwgit commented Dec 18, 2023

Description

Not all apps will need to immediately log into the POD on startup. An example is BSTIM which only needs PODs when a survey is to be submitted. This use case is for a solid pod login popup that will establish a connection to the pod.

If a WebID is not known then prompt for it and save it locally, then connect to the server to retrieve the token.

The token should be retained so that no further login is required for reading/writing data during the app session.

If the app folder does not exist for the user on the solid server then run the InitialisePod() widget from #2

Closing Criteria

  • This popup is deployed into bstim
  • This popup is deployed into keypod on the LOAD button
@gjwgit gjwgit assigned junhaow1 and zheyxu and unassigned junhaow1 Dec 18, 2023
@gjwgit gjwgit changed the title SOLID CORE: Create PodLoginPopup SOLID AUTH: Create PodLoginPopup Dec 19, 2023
@gjwgit gjwgit changed the title SOLID AUTH: Create PodLoginPopup SOLID: Create SolidLoginPopup Dec 22, 2023
@gjwgit gjwgit transferred this issue from anusii/solid-core Dec 22, 2023
@gjwgit gjwgit changed the title SOLID: Create SolidLoginPopup SOLID: Create SolidLoginPopup() Dec 22, 2023
@gjwgit gjwgit changed the title SOLID: Create SolidLoginPopup() SOLIDPOD: Implement PopupLogin() for bstim, innerpod Feb 8, 2024
@gjwgit
Copy link
Contributor Author

gjwgit commented Feb 14, 2024

Could this be assigned to Kevin? Start to have a look at how this will work. Thanks.

@junhaow1
Copy link
Collaborator

Assign myself to this ticket

@junhaow1
Copy link
Collaborator

@junhaow1
Copy link
Collaborator

junhaow1 commented Feb 28, 2024

image image image

@junhaow1
Copy link
Collaborator

junhaow1 commented Feb 28, 2024

solidpod repo:
#57

keypod repo:
anusii/keypod#51

PR created

@junhaow1
Copy link
Collaborator

junhaow1 commented Mar 6, 2024

in progress, working on saving auth data/token for use on other pages as in SolidLogin()

@gjwgit gjwgit changed the title SOLIDPOD: Implement PopupLogin() for bstim, innerpod SOLIDPOD: Implement SolidloginPopup() for bstim, innerpod Mar 12, 2024
@gjwgit gjwgit changed the title SOLIDPOD: Implement SolidloginPopup() for bstim, innerpod SOLIDPOD: Implement SolidloginPopup() for bstim Mar 12, 2024
@gjwgit gjwgit changed the title SOLIDPOD: Implement SolidloginPopup() for bstim SOLIDPOD: Implement SolidLoginPopup() for bstim Mar 12, 2024
@junhaow1
Copy link
Collaborator

junhaow1 commented Mar 13, 2024

I converted authdata (Map format) into String using serializeMap so that we can save them in secureStorage. But I found difficulty converting the string back to the correct map format. Dawei suggested I can convert the map into Json format first, then save as a string using secureStorage.

@cdawei cdawei mentioned this issue Mar 14, 2024
19 tasks
@cdawei
Copy link
Collaborator

cdawei commented Mar 14, 2024

This page might be useful for converting the authData between a String and a Map https://docs.flutter.dev/data-and-backend/serialization/json

@junhaow1
Copy link
Collaborator

/// Store authentication data
authData = {
'client': client,
'rsaInfo': rsaResults,
'authResponse': authResponse,
'tokenResponse': tokenResponse,
'accessToken': accessToken,
'idToken': tokenResponse.idToken,
'refreshToken': tokenResponse.refreshToken,
'expiresIn': tokenResponse.expiresIn,
'logoutUrl': _logoutUrl
};

how to Serialize JSON for each map value .

error I got: Converting object to an encodable object failed: Instance of 'Client’

@cdawei
Copy link
Collaborator

cdawei commented Mar 15, 2024

So Anushka mentioned that re-creating the client instance can be done through:

var client = Client(issuer, _clientId, clientSecret: _clientSecret);

where both the _clientId and _clientSecret are strings (so can be serialised).
The issuer variable can be recreated through:

Issuer issuer = await Issuer.discover(issuerUri);

where issuerUri is the same as the one when calling the authenticate function.

Therefore, it seems that we should be able to recreate the client instance by saving the _clientId, _clientSecret and issuerUri.

@junhaow1
Copy link
Collaborator

So Anushka mentioned that re-creating the client instance can be done through:

var client = Client(issuer, _clientId, clientSecret: _clientSecret);

where both the _clientId and _clientSecret are strings (so can be serialised). The issuer variable can be recreated through:

Issuer issuer = await Issuer.discover(issuerUri);

where issuerUri is the same as the one when calling the authenticate function.

Therefore, it seems that we should be able to recreate the client instance by saving the _clientId, _clientSecret and issuerUri.

Thanks @cdawei on it

@junhaow1
Copy link
Collaborator

demo video:

image
video1107929422.mp4

@junhaow1
Copy link
Collaborator

junhaow1 commented Mar 18, 2024

       // Get the authentication data from the secure storage.

                                      const storage =
                                          FlutterSecureStorage();
                                      String? jsonAuthData = await storage
                                          .read(key: 'authData');
                                      Map<String, dynamic> deserializedMap =
                                          json.decode(jsonAuthData!);
                                      var rsaInfo =
                                          deserializedMap['rsaInfo'];
                                      KeyPair deserializedKeyPair = KeyPair(
                                        rsaInfo['rsa']['publicKey'],
                                        rsaInfo['rsa']['privateKey'],
                                      );
                                      var pubKeyJwk = rsaInfo['pubKeyJwk'];
                                      Map<String, dynamic> authData = {
                                        'accessToken':
                                            deserializedMap['accessToken'],
                                        'rsaInfo': {
                                          'rsa': deserializedKeyPair,
                                          'pubKeyJwk': pubKeyJwk,
                                        },
                                      };
image

@junhaow1
Copy link
Collaborator

@gjwgit
Copy link
Contributor Author

gjwgit commented Mar 19, 2024

Let's review this today - that it is fully functional.

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

No branches or pull requests

5 participants