make sure we wait for the token to be stored before reloading the page.

This commit is contained in:
Jason Kulatunga 2022-09-14 08:19:28 -07:00
parent edd8587ab2
commit f845ae3716
5 changed files with 25 additions and 40 deletions

View File

@ -66,5 +66,15 @@ func (c *configuration) ReadConfig(configFilePath string) error {
log.Printf("Error merging config file: %s", err)
return err
}
return c.ValidateConfig()
}
// This function ensures that required configuration keys (that must be manually set) are present
func (c *configuration) ValidateConfig() error {
if !c.IsSet("web.jwt.encryptionkey") {
return errors.ConfigValidationError("`web.jwt.encryptionkey` configuration option must be set")
}
return nil
}

View File

@ -26,7 +26,7 @@ func AuthSignup(c *gin.Context) {
}
// return JWT
tokenString, err := auth.GenerateJWT(appConfig.GetString("web.jwt.encryptionKey"), user.Username)
tokenString, err := auth.GenerateJWT(appConfig.GetString("web.jwt.encryptionkey"), user.Username)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
return
@ -58,7 +58,7 @@ func AuthSignin(c *gin.Context) {
}
// return JWT
tokenString, err := auth.GenerateJWT(appConfig.GetString("web.jwt.encryptionKey"), user.Username)
tokenString, err := auth.GenerateJWT(appConfig.GetString("web.jwt.encryptionkey"), user.Username)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": "an error occurred generating JWT token"})
return

View File

@ -30,7 +30,7 @@ func RequireAuth() gin.HandlerFunc {
c.Abort()
return
}
claim, err := auth.ValidateToken(appConfig.GetString("web.jwt.encryptionKey"), tokenString)
claim, err := auth.ValidateToken(appConfig.GetString("web.jwt.encryptionkey"), tokenString)
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": err.Error()})
c.Abort()

View File

@ -8,7 +8,7 @@ version: 1
web:
jwt:
# used to encrypt/validate JWT session key (used for authentication)
encryptionKey: 'changethissupersecretkey'
encryptionkey: 'changethissupersecretkey'
listen:
port: 9090
host: 0.0.0.0

View File

@ -143,44 +143,19 @@ export class MedicalSourcesComponent implements OnInit {
code_verifier: codeVerifier,
}
this.fastenApi.createSource(sourceCredential).subscribe( (respData) => {
console.log("source credential create response:", respData)
})
await this.fastenApi.createSource(sourceCredential).subscribe(
(respData) => {
console.log("source credential create response:", respData)
},
(err) => {console.log(err)},
() => {
delete this.status[sourceType]
//reload the current page after finishing connection
window.location.reload();
}
)
// console.log("STARTING--- FHIR.client(clientState)", clientState)
// const fhirClient = FHIR.client(clientState);
//
// console.log("STARTING--- client.request(Patient)")
// const patientResponse = await fhirClient.request("PatientAccess/v1/$userinfo")
// console.log(patientResponse)
// // fetch userinfo response
//
// const response = await oauth.userInfoRequest(as, client, access_token)
//
// let challenges: oauth.WWWAuthenticateChallenge[] | undefined
// if ((challenges = oauth.parseWwwAuthenticateChallenges(response))) {
// for (const challenge of challenges) {
// console.log('challenge', challenge)
// }
// throw new Error() // Handle www-authenticate challenges as needed
// }
//
// const result = await oauth.processUserInfoResponse(as, client, sub, response)
// console.log('result', result)
delete this.status[sourceType]
//reload the current page after finishing connection
window.location.reload();
})
});