Title: | Authentication for 'Shiny' Apps with 'Amazon Cognito' |
---|---|
Description: | Provides authentication for Shiny applications using 'Amazon Cognito' ( <https://aws.amazon.com/es/cognito/>). |
Authors: | Pablo Pagnone [aut, cre], Aleksander Dietrichson [aut] |
Maintainer: | Pablo Pagnone <[email protected]> |
License: | GPL-3 |
Version: | 1.0.4 |
Built: | 2025-02-22 03:40:03 UTC |
Source: | https://github.com/chi2labs/cognitor |
This method is working with amazing package "paws" , so you need to have the required AWS secret and access key (see example).
cognito_add_account( cognito_config, Username, UserAttributes, DesiredDeliveryMediums, ... )
cognito_add_account( cognito_config, Username, UserAttributes, DesiredDeliveryMediums, ... )
cognito_config |
- Cognito Config list |
Username |
- Username to use in Cognito - This can be a username, email ,phone depending configuration in Amazon Pool. |
UserAttributes |
- User attributes: This can be multiples attributes, depends of configuration in Amazon Pool. |
DesiredDeliveryMediums |
- Medium to delivert email when user is created, can be EMAIL or SMS |
... |
extra params to pass to method paws::admin_create_user |
Also needs to have the config for cognitoR. Specially the pool Id (group_id in config), where the new user is created.
boolean
## Not run: Sys.setenv( AWS_ACCESS_KEY_ID = '', AWS_SECRET_ACCESS_KEY = '', AWS_REGION = '' ) cognito_add_account("[email protected]", UserAttributes = list(list(Name = "email", Value = "[email protected]"), list(Name = "phone_number", Value = "+12123212312321") ), DesiredDeliveryMediums = "EMAIL" ) ## End(Not run)
## Not run: Sys.setenv( AWS_ACCESS_KEY_ID = '', AWS_SECRET_ACCESS_KEY = '', AWS_REGION = '' ) cognito_add_account("[email protected]", UserAttributes = list(list(Name = "email", Value = "[email protected]"), list(Name = "phone_number", Value = "+12123212312321") ), DesiredDeliveryMediums = "EMAIL" ) ## End(Not run)
A shiny server function to implement Cognito Authentication in your shiny app.
cognito_server( input, output, session, with_cookie = FALSE, cookiename = "cognitor", cookie_expire = 7 )
cognito_server( input, output, session, with_cookie = FALSE, cookiename = "cognitor", cookie_expire = 7 )
input |
- Shiny input |
output |
- Shiny Output |
session |
- Shiny Session |
with_cookie |
- Create a own cookie when is authenticated in Cognito. |
cookiename |
- name for cookie |
cookie_expire |
- Expiration time for cookie |
reactiveValues (isLogged and userdata) and a callback function to do logout in Cognito.
Pablo Pagnone
A Shiny UI function to be used to implement Amazon Cognito in your shiny app. This UI loads the required JS.
cognito_ui(id)
cognito_ui(id)
id |
character - Namespace ID |
A Shiny UI
Pablo Pagnone
cognito_ui("demo")
cognito_ui("demo")
This server module returns a list with methods to interact with cookie created via JS. You have:
cookie_server(input, output, session, cookie_name = "user", cookie_expire = 7)
cookie_server(input, output, session, cookie_name = "user", cookie_expire = 7)
input |
shiny input |
output |
shiny output |
session |
shiny session |
cookie_name |
character - Name of cookie to create |
cookie_expire |
numeric - Expiration timeof cookie |
getCookie - Reactive function, returns the content of cookie if exist. Else return FALSE.
setCookie - Sets the content for a cookie. (Required param: list())
rmCookie - Removes a cookie
list of reactive element and function to manage cookies
Pablo Pagnone
cookie_server(NULL,NULL,NULL)
cookie_server(NULL,NULL,NULL)
This UI module load the required js methods to create/remove/get cookie in browser.
cookie_ui(id)
cookie_ui(id)
id |
character |
a Shiny UI
cookie_ui("cookie")
cookie_ui("cookie")
Receive a reactive element (isLogged), when is TRUE the logout button and information about is shown.
logout_server( input, output, session, isLogged = reactive(FALSE), textlogged = "You are logged in" )
logout_server( input, output, session, isLogged = reactive(FALSE), textlogged = "You are logged in" )
input |
Shiny input |
output |
Shiny output |
session |
Shiny session |
isLogged |
reactive |
textlogged |
character |
reactive (the logout button)
logout_server(NULL, NULL, NULL)
logout_server(NULL, NULL, NULL)
Return a UI with a logout button and information about user logged. By default is hidden and is show with reactive element from logoutServer
logout_ui(id, textbutton = "Log out", classbutton = "btn-logout btn-danger")
logout_ui(id, textbutton = "Log out", classbutton = "btn-logout btn-danger")
id |
character |
textbutton |
character |
classbutton |
character |
Shiny UI
logout_ui("test")
logout_ui("test")