-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from aappling-usgs/master
changes to session validation/renewal
- Loading branch information
Showing
11 changed files
with
107 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: sbtools | ||
Title: USGS ScienceBase Tools | ||
Maintainer: Luke Winslow <[email protected]> | ||
Version: 0.15.2 | ||
Version: 0.15.3 | ||
Authors@R: c(person("Luke", "Winslow", role = c("aut","cre"), | ||
email = "[email protected]"), | ||
person("Scott", "Chamberlain", role = c("aut"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#' Checks current session and re-authenticates if necessary | ||
#' | ||
#' Checks the state of your Sciencebase session, re-authenticates if the session | ||
#' is expired, and simply renews if the session is active. | ||
#' | ||
#' @param password The password to use, if needed, to renew the session. | ||
#' @param username Optional. Used only to confirm that the current username is | ||
#' what you expect; if you want to switch usernames, use | ||
#' \code{authenticate_sb()} instead of this function. | ||
#' @param session SB session object from \code{\link{authenticate_sb}}. Default | ||
#' is the current session. | ||
#' @param ... Any additional parameters are currently ignored. | ||
#' | ||
#' @return Returns the session object. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' # an empty call is sufficient if the session is current, | ||
#' # but will break if haven't been logged in before | ||
#' session_renew() | ||
#' | ||
#' # include a password if session may be expired | ||
#' session_renew('newpass') | ||
#' | ||
#' # optionally confirm the value of the current username | ||
#' session_renew(username='[email protected]', 'newpass') | ||
#' } | ||
#' @import httr | ||
#' @export | ||
session_renew = function(password, ..., username, session=current_session()){ | ||
|
||
# if we'll need the current username, find it now. use the existing session | ||
# info on SB if available; otherwise use the username stored locally | ||
if(!missing(username) || !is_logged_in(session=session)) { | ||
sb_username <- session_details(session=session)$username | ||
if(is.null(sb_username)) sb_username <- pkg.env$username | ||
} | ||
|
||
# if username is provided, confirm that it matches the stored username | ||
if(!missing(username)) { | ||
if(username != sb_username) { | ||
stop("username argument does not match session username") | ||
} | ||
} | ||
|
||
# either renew or re-authenticate as needed | ||
if(is_logged_in(session=session)) { | ||
# the GET call to 'status' resets the remote (SB) info on session age, while | ||
# sbtools_GET resets the local info on session age | ||
sbtools_GET(url=paste0(pkg.env$url_base, "status?format=json"), session=session) | ||
invisible(session) | ||
} else { | ||
# re-authenticate, handling missing parameters as needed | ||
if(sb_username=="") stop("new authentication is necessary; call authenticate_sb()") | ||
if(missing(password)) stop("re-authentication is necessary; need password") | ||
invisible(authenticate_sb(sb_username, password)) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters