RCognito is an R package designed to simplify interaction with Amazon Cognito services through a user-friendly API wrapper. Seamlessly authenticate users, manage user pools, and perform common Cognito operations in R. Empower your R applications with secure and scalable identity management using Rcognito.
You can install the RCognito
package directly from
GitHub using the remotes
package:
# Install remotes package if not already installed
install.packages("remotes")
# Install RCognito from GitHub
::install_github("SanjayShetty01/RCognito") remotes
Before using the RCognito package, make sure to set your AWS credentials. You can do this in either of the following ways:
.Renviron
FileCreate or edit the .Renviron
file in your R home
directory and add the following:
AWS_ACCESS_KEY_ID="your-access-key-id"
AWS_SECRET_ACCESS_KEY="your-secret-access-key"
AWS_REGION="your-region"
Sys.setenv()
FunctionAlternatively, you can set the AWS credentials programmatically using
the Sys.setenv()
function in your R script or session:
# Set AWS credentials
Sys.setenv(AWS_ACCESS_KEY_ID = "your-access-key-id")
Sys.setenv(AWS_SECRET_ACCESS_KEY = "your-secret-access-key")
Sys.setenv(AWS_REGION = "your-region")
The sign_up_user
function allows you to sign up a new
user in AWS Cognito. It accepts the client_id
,
email
, username
, and password
parameters.
library(Rcognito)
# Sign up a new user
sign_up_user(
client_id = "your-client-id",
email = "user@example.com",
username = "johndoe",
password = "password123"
)
client_id
: Your AWS Cognito App client ID.email
: The user’s email address.username
: The user’s desired username.password
: The user’s password.Once a user has signed up, you need to confirm their sign-up using
the verification code sent to their email. The
confirm_sign_up_user
function helps with this.
# Confirm user sign-up
confirm_sign_up_user(
client_id = "your-client-id",
userpool = "your-userpool-id",
username = "johndoe",
verification_code = "123456"
)
client_id
: Your AWS Cognito App client ID.userpool
: Your AWS Cognito User Pool ID.username
: The username of the user to confirm.verification_code
: The verification code sent to the
user’s email.Once a user is confirmed, they can sign in using their
username
and password
with the
sign_in
function.
# Sign in a user
<- sign_in(
user_info client_id = "your-client-id",
username = "johndoe",
password = "password123"
)
# View user information
print(user_info)
client_id
: Your AWS Cognito App client ID.username
: The username of the user to sign in.password
: The user’s password.Use the change_password
function to change a user’s
password after they are authenticated.
# Change user password
change_password(
old_password = "old-password",
new_password = "new-password",
token = "user-access-token"
)
old_password
: The current password of the user.new_password
: The new password for the user.token
: The user’s access token.If a user forgets their password, use the
forgot_password
function to initiate the password reset
process.
# Initiate forgot password request
forgot_password(
client_id = "your-client-id",
username = "johndoe"
)
client_id
: Your AWS Cognito App client ID.username
: The username of the user who forgot their
password.After receiving a confirmation code, use the
confirm_forgot_password
function to set a new password.
# Confirm forgot password with new password and confirmation code
confirm_forgot_password(
client_id = "your-client-id",
username = "johndoe",
confirmation_code = "confirmation-code",
new_password = "new-password"
)
client_id
: Your AWS Cognito App client ID.username
: The username of the user confirming their
forgot password.confirmation_code
: The confirmation code sent to the
user.new_password
: The new password the user wants to
set.RCognito
RCognito
allows you to integrate AWS Cognito for user
authentication in Shiny applications. It enables secure user sign-up,
sign-in, password management and session management, making restricting
access to sensitive features based on authenticated user roles
easier.
RCognito
can be used to secure API endpoints in a
Plumber service by validating AWS Cognito authentication tokens. This
ensures that only authorized users can access specific API endpoints and
perform actions that require authentication.
When using R scripts for backend operations (e.g., data analysis, API
interaction), RCognito
facilitates secure authentication by
verifying user credentials before allowing access to sensitive tasks or
data.
This project is licensed under the MIT License - see the LICENSE file for details.