Add removePasswordOnLogin setting
parent
bec1ae4a3b
commit
e8c0df004e
|
@ -1,6 +1,7 @@
|
||||||
module Internal.Config.Default exposing
|
module Internal.Config.Default exposing
|
||||||
( currentVersion, deviceName
|
( currentVersion, deviceName
|
||||||
, syncTime
|
, syncTime
|
||||||
|
, removePasswordOnLogin
|
||||||
)
|
)
|
||||||
|
|
||||||
{-| This module hosts all default settings and configurations that the Vault
|
{-| This module hosts all default settings and configurations that the Vault
|
||||||
|
@ -16,6 +17,11 @@ will assume until overriden by the user.
|
||||||
|
|
||||||
@docs syncTime
|
@docs syncTime
|
||||||
|
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
@docs removePasswordOnLogin
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,3 +58,13 @@ The value is in miliseconds, so it is set at 30,000.
|
||||||
syncTime : Int
|
syncTime : Int
|
||||||
syncTime =
|
syncTime =
|
||||||
30 * 1000
|
30 * 1000
|
||||||
|
|
||||||
|
|
||||||
|
{-| Once the Matrix API has logged in successfully, it does not need to remember
|
||||||
|
the user's password. However, to keep the Vault logged in automatically, one may
|
||||||
|
choose to remember the password in order to get a new access token when an old
|
||||||
|
access token has expired.
|
||||||
|
-}
|
||||||
|
removePasswordOnLogin : Bool
|
||||||
|
removePasswordOnLogin =
|
||||||
|
True
|
||||||
|
|
|
@ -321,6 +321,7 @@ fields :
|
||||||
, settings :
|
, settings :
|
||||||
{ currentVersion : Desc
|
{ currentVersion : Desc
|
||||||
, deviceName : Desc
|
, deviceName : Desc
|
||||||
|
, removePasswordOnLogin : Desc
|
||||||
, syncTime : Desc
|
, syncTime : Desc
|
||||||
}
|
}
|
||||||
, timeline :
|
, timeline :
|
||||||
|
@ -501,6 +502,9 @@ fields =
|
||||||
, deviceName =
|
, deviceName =
|
||||||
[ "Indicates the device name that is communicated to the Matrix API."
|
[ "Indicates the device name that is communicated to the Matrix API."
|
||||||
]
|
]
|
||||||
|
, removePasswordOnLogin =
|
||||||
|
[ "Remove the password as soon as a valid access token has been received."
|
||||||
|
]
|
||||||
, syncTime =
|
, syncTime =
|
||||||
[ "Indicates the frequency in miliseconds with which the Elm SDK should long-poll the /sync endpoint."
|
[ "Indicates the frequency in miliseconds with which the Elm SDK should long-poll the /sync endpoint."
|
||||||
]
|
]
|
||||||
|
|
|
@ -35,6 +35,7 @@ behave under the user's preferred settings.
|
||||||
type alias Settings =
|
type alias Settings =
|
||||||
{ currentVersion : String
|
{ currentVersion : String
|
||||||
, deviceName : String
|
, deviceName : String
|
||||||
|
, removePasswordOnLogin : Bool
|
||||||
, syncTime : Int
|
, syncTime : Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +44,7 @@ type alias Settings =
|
||||||
-}
|
-}
|
||||||
coder : Json.Coder Settings
|
coder : Json.Coder Settings
|
||||||
coder =
|
coder =
|
||||||
Json.object3
|
Json.object4
|
||||||
{ name = Text.docs.settings.name
|
{ name = Text.docs.settings.name
|
||||||
, description = Text.docs.settings.description
|
, description = Text.docs.settings.description
|
||||||
, init = Settings
|
, init = Settings
|
||||||
|
@ -66,6 +67,21 @@ coder =
|
||||||
, defaultToString = identity
|
, defaultToString = identity
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
(Json.field.optional.withDefault
|
||||||
|
{ fieldName = "removePasswordOnLogin"
|
||||||
|
, toField = .removePasswordOnLogin
|
||||||
|
, description = Text.fields.settings.removePasswordOnLogin
|
||||||
|
, coder = Json.bool
|
||||||
|
, default = Tuple.pair Default.removePasswordOnLogin []
|
||||||
|
, defaultToString =
|
||||||
|
\b ->
|
||||||
|
if b then
|
||||||
|
"true"
|
||||||
|
|
||||||
|
else
|
||||||
|
"false"
|
||||||
|
}
|
||||||
|
)
|
||||||
(Json.field.optional.withDefault
|
(Json.field.optional.withDefault
|
||||||
{ fieldName = "syncTime"
|
{ fieldName = "syncTime"
|
||||||
, toField = .syncTime
|
, toField = .syncTime
|
||||||
|
@ -97,5 +113,6 @@ init : Settings
|
||||||
init =
|
init =
|
||||||
{ currentVersion = Default.currentVersion
|
{ currentVersion = Default.currentVersion
|
||||||
, deviceName = Default.deviceName
|
, deviceName = Default.deviceName
|
||||||
|
, removePasswordOnLogin = Default.removePasswordOnLogin
|
||||||
, syncTime = Default.syncTime
|
, syncTime = Default.syncTime
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ module Matrix.Settings exposing
|
||||||
( setAccessToken, removeAccessToken
|
( setAccessToken, removeAccessToken
|
||||||
, getDeviceName, setDeviceName
|
, getDeviceName, setDeviceName
|
||||||
, getSyncTime, setSyncTime
|
, getSyncTime, setSyncTime
|
||||||
|
, setPassword
|
||||||
|
, removePassword, removePasswordOnLogin
|
||||||
)
|
)
|
||||||
|
|
||||||
{-| The Matrix Vault has lots of configurable variables that you rarely want to
|
{-| The Matrix Vault has lots of configurable variables that you rarely want to
|
||||||
|
@ -50,20 +52,39 @@ The value is in miliseconds, so it is set at 30,000.
|
||||||
|
|
||||||
@docs getSyncTime, setSyncTime
|
@docs getSyncTime, setSyncTime
|
||||||
|
|
||||||
|
|
||||||
|
## Password
|
||||||
|
|
||||||
|
When a Vault wants to access the Matrix API, it needs an access token. This can
|
||||||
|
either be provided directly, or the Vault can get one itself by using a password
|
||||||
|
to log in.
|
||||||
|
|
||||||
|
@docs setPassword
|
||||||
|
|
||||||
|
For security reasons, it is not possible to read whatever password is stored in
|
||||||
|
the Vault. An attacker with access to the memory might be able to find it,
|
||||||
|
however, so the Vault offers ways to remove the password from memory.
|
||||||
|
|
||||||
|
@docs removePassword, removePasswordOnLogin
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
import Internal.Values.Envelope as Envelope
|
import Internal.Values.Envelope as Envelope
|
||||||
import Types exposing (Vault(..))
|
import Types exposing (Vault(..))
|
||||||
|
|
||||||
|
|
||||||
{-| Insert a suggested access token.
|
{-| Determine the device name.
|
||||||
-}
|
-}
|
||||||
setAccessToken : String -> Vault -> Vault
|
getDeviceName : Vault -> String
|
||||||
setAccessToken token (Vault vault) =
|
getDeviceName (Vault vault) =
|
||||||
vault
|
Envelope.extractSettings .deviceName vault
|
||||||
|> Envelope.mapContext
|
|
||||||
(\c -> { c | suggestedAccessToken = Just token })
|
|
||||||
|> Vault
|
{-| Determine the sync timeout value.
|
||||||
|
-}
|
||||||
|
getSyncTime : Vault -> Int
|
||||||
|
getSyncTime (Vault vault) =
|
||||||
|
Envelope.extractSettings .syncTime vault
|
||||||
|
|
||||||
|
|
||||||
{-| Remove an access token that has been inserted using the
|
{-| Remove an access token that has been inserted using the
|
||||||
|
@ -80,11 +101,32 @@ removeAccessToken (Vault vault) =
|
||||||
|> Vault
|
|> Vault
|
||||||
|
|
||||||
|
|
||||||
{-| Determine the device name.
|
{-| Remove a password that is stored in the Matrix Vault.
|
||||||
-}
|
-}
|
||||||
getDeviceName : Vault -> String
|
removePassword : Vault -> Vault
|
||||||
getDeviceName (Vault vault) =
|
removePassword (Vault vault) =
|
||||||
Envelope.extractSettings .deviceName vault
|
vault
|
||||||
|
|> Envelope.mapContext
|
||||||
|
(\c -> { c | password = Nothing })
|
||||||
|
|> Vault
|
||||||
|
|
||||||
|
|
||||||
|
{-| Remove password from the Vault as soon as a valid access token has been
|
||||||
|
received from the Matrix API.
|
||||||
|
-}
|
||||||
|
removePasswordOnLogin : Bool -> Vault -> Vault
|
||||||
|
removePasswordOnLogin b (Vault vault) =
|
||||||
|
Vault <| Envelope.mapSettings (\s -> { s | removePasswordOnLogin = b }) vault
|
||||||
|
|
||||||
|
|
||||||
|
{-| Insert a suggested access token.
|
||||||
|
-}
|
||||||
|
setAccessToken : String -> Vault -> Vault
|
||||||
|
setAccessToken token (Vault vault) =
|
||||||
|
vault
|
||||||
|
|> Envelope.mapContext
|
||||||
|
(\c -> { c | suggestedAccessToken = Just token })
|
||||||
|
|> Vault
|
||||||
|
|
||||||
|
|
||||||
{-| Override the device name.
|
{-| Override the device name.
|
||||||
|
@ -94,11 +136,14 @@ setDeviceName name (Vault vault) =
|
||||||
Vault <| Envelope.mapSettings (\s -> { s | deviceName = name }) vault
|
Vault <| Envelope.mapSettings (\s -> { s | deviceName = name }) vault
|
||||||
|
|
||||||
|
|
||||||
{-| Determine the sync timeout value.
|
{-| Set a password for the given user.
|
||||||
-}
|
-}
|
||||||
getSyncTime : Vault -> Int
|
setPassword : String -> Vault -> Vault
|
||||||
getSyncTime (Vault vault) =
|
setPassword password (Vault vault) =
|
||||||
Envelope.extractSettings .syncTime vault
|
vault
|
||||||
|
|> Envelope.mapContext
|
||||||
|
(\c -> { c | password = Just password })
|
||||||
|
|> Vault
|
||||||
|
|
||||||
|
|
||||||
{-| Override the sync timeout value.
|
{-| Override the sync timeout value.
|
||||||
|
|
Loading…
Reference in New Issue