Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for selection of Auth Provider #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions R/get_session_key.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#' This function logs into the LimeSurvey API and provides an access session key.
#' @param username LimeSurvey username. Defaults to value set in \code{options()}.
#' @param password LimeSurvey password Defaults to value set in \code{options()}.
#' @param auth LimeSurvey Auth Plugin Defaults to value set in \code{options() - if no value set uses Authdb}.
#' @return API token
#' @import httr
#' @export
Expand All @@ -11,11 +12,13 @@
#' }

get_session_key <- function(username = getOption('lime_username'),
password = getOption('lime_password')) {
password = getOption('lime_password'),
plugin = getOption('lime_auth',default='Authdb')) {
body.json = list(method = "get_session_key",
id = " ",
params = list(username = username,
password = password))
password = password,
plugin = plugin))

# Need to use jsonlite::toJSON because single elements are boxed in httr, which
# is goofy. toJSON can turn off the boxing automatically, though it's not
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Load your API details and user credentials into R using `options()`:
options(lime_api = 'http://example.com/limesurvey/admin/remotecontrol')
options(lime_username = 'put_username_here')
options(lime_password = 'put_password_here')
options(lime_auth = 'AuthLDAP')
```
lime_auth is an optional parameter. If you do not set it, it will default to 'Authdb', which is the standard way of authentication in LimeSurvey. But if the LimeSurvey installation is set to use LDAP for authentication (as in many Universities), set it to 'AuthLDAP'.

Before calling the API, you need to generate an access token with `get_session_key()` (examples of how to do this are shown below). Many services provide tokens that last indefinitely, but by default LimeSurvey's will only last for two hours. (this can be modified by editing `limesurvey/application/config/config-default.php` and changing `$config['iSessionExpirationTime'] = 7200;` to something else).

Expand All @@ -32,6 +34,7 @@ library(limer)
options(lime_api = 'http://example.com/limesurvey/admin/remotecontrol')
options(lime_username = 'put_username_here')
options(lime_password = 'put_password_here')
options(lime_auth = 'AuthLDAP')

# Do stuff with LimeSurvey API
get_session_key() # Log in
Expand Down