Skip to content

Authentication and identifying Google users using Google+ API

License

Notifications You must be signed in to change notification settings

pinklite34/googleID

This branch is 23 commits ahead of, 4 commits behind MarkEdmondson1234/googleID:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Feb 13, 2020
f3e94ae · Feb 13, 2020

History

38 Commits
Jul 3, 2016
Sep 6, 2019
Jul 3, 2016
Mar 17, 2016
Jul 3, 2016
Jul 3, 2016
Mar 17, 2016
Jul 3, 2016
Dec 3, 2017
Feb 12, 2020
Feb 13, 2020
Feb 13, 2020
Feb 12, 2020
Feb 12, 2020
Feb 13, 2020
Feb 12, 2020
Feb 12, 2020
Feb 12, 2020
Feb 13, 2020
Feb 12, 2020
Mar 17, 2016
Feb 13, 2020
Feb 12, 2020
Feb 12, 2020
Feb 12, 2020
Feb 13, 2020
Feb 13, 2020
Feb 12, 2020
Feb 12, 2020
Feb 12, 2020
Feb 13, 2020

Repository files navigation

googleID

Travis-CI Build Status

Authentication and identifying Google users using Google+ API

Example

Activate Google+ API here

Download your Google Project's client JSON as detailed in googleAuthR help

library(googleAuthR)
library(googleID)

## set your client ID/secret and scopes
gar_set_client("location_of_client.json",
               scopes = c("https://www.googleapis.com/auth/userinfo.email",
                          "https://www.googleapis.com/auth/userinfo.profile"))

# or if you have downloaded service auth JSON, gar_service_auth()
gar_auth()

## default is user logged in
user <- get_user_info()

> str(user)
List of 24
 $ kind          : chr "plus#person"
 $ etag          : chr "\"4OZ_Kt6ujOh1jaML_U6RM6APqoE/UYyiZzYR_iS62bMpKv92P1iPcZ0\""
 $ occupation    : chr "Google Developer Expert - Google Analytics.  RStudio Advocate."
 $ skills        : chr "Google Analytics, Adobe Marketing Cloud, R, Python, SEO, Google Cloud, Statistics, Music"
 $ gender        : chr "male"
 $ emails        :'data.frame':	1 obs. of  2 variables:
  ..$ value: chr "me@markedmondson.me"
  ..$ type : chr "account"
 $ urls          :'data.frame':	5 obs. of  3 variables:
  ..$ value: chr [1:5] "http://twitter.com/holomarked" "http://www.linkedin.com/in/markpeteredmondson" "https://github.com/MarkEdmondson1234" "http://stackoverflow.com/users/3878063/marked" ...
  ..$ type : chr [1:5] "otherProfile" "otherProfile" "otherProfile" "otherProfile" ...
  ..$ label: chr [1:5] "Twitter" "Mark Edmondson LinkedIn" "Github" "StackOverflow" ...
 $ objectType    : chr "person"
 $ id            : chr "115064340704113209584"
 $ displayName   : chr "Mark Edmondson"
 $ name          :List of 2
  ..$ familyName: chr "Edmondson"
  ..$ givenName : chr "Mark"
 $ tagline       : chr "Taking part in the evolution of the Multivac"
 $ braggingRights: chr "RStudio Advocate.  Google Developer Expert - Google Analytics.  Adobe Certified Expert - Adobe Analytics."
 $ aboutMe       : chr "Taking part in the evolution of the multivac<br />"
 $ url           : chr "https://plus.google.com/+MarkEdmondsonAtHome"
 $ image         :List of 2
  ..$ url      : chr "https://lh5.googleusercontent.com/-OVYhmgQg3lg/AAAAAAAAAAI/AAAAAAAAAP0/1qVcsNpSXlQ/photo.jpg?sz=50"
  ..$ isDefault: logi FALSE
 $ organizations :'data.frame':	1 obs. of  4 variables:
  ..$ name   : chr "King's College London"
  ..$ title  : chr "Physics"
  ..$ type   : chr "school"
  ..$ primary: logi FALSE
 $ placesLived   :'data.frame':	3 obs. of  1 variable:
  ..$ value: chr [1:3] "Copenhagen" "London" "Falmouth, UK"
 $ isPlusUser    : logi TRUE
 $ language      : chr "en_GB"
 $ circledByCount: int 410
 $ verified      : logi FALSE
 $ cover         :List of 3
  ..$ layout    : chr "banner"
  ..$ coverPhoto:List of 3
  .. ..$ url   : chr "https://lh3.googleusercontent.com/HIq8ABRcUKBs5AYBg0tiqoJifjv3A08MWCU3u79hBWhXjvBv1iilf94_YIjRSH4VlWZH=s630"
  .. ..$ height: int 183
  .. ..$ width : int 940
  ..$ coverInfo :List of 2
  .. ..$ topImageOffset : int 0
  .. ..$ leftImageOffset: int 0
 $ domain        : chr "markedmondson.me"

Use within Shiny

library(shiny)
library(googleAuthR)
library(googleID)

# set scopes
gar_set_client(scopes = c("https://www.googleapis.com/auth/userinfo.email",
                                       "https://www.googleapis.com/auth/userinfo.profile"))

## set your web app client ID/secret and scopes
options(googleAuthR.webapp.client_id = getOption("googleAuthR.client_id"),
        googleAuthR.webapp.client_secret = getOption("googleAuthR.client_secret"))

ui <- shinyUI(fluidPage(
  
  googleAuthUI("example1"),
  p("Logged in as: ", textOutput("user_name"))
  
))


server <- shinyServer(function(input, output, session) {
  
  access_token <- callModule(googleAuth, "example1")
  
  ## to use in a shiny app:
  user_details <- reactive({
    validate(
      need(access_token(), "Authenticate")
    )
    
    with_shiny(get_user_info, shiny_access_token = access_token())
    
  })
  
  output$user_name <- renderText({
    validate(
      need(user_details(), "getting user details")
    )
    
    user_details()$displayName
    
  })
  
  
})

# Run the application 
shinyApp(ui = ui, server = server)

Shiny/RMarkdown via JavaScript auth plugin

Alternatively, you can also login via javascript in RMarkdown documents, but this requires the dev version of googleAuthR.
A demo and how to of this is available in this RMarkdown document: https://mark.shinyapps.io/googleAuthRMarkdown/

Whitelist

The function whitelist() can be used to return TRUE or FALSE is the user is on a supplied list.

You can supply the whitelist as a character vector, which could be imported from a file or similar.

To use, pass the user object to the function with the whitelist like this:

library(googleAuthR)
library(googleID)

## set your client ID/secret and scopes
gar_set_client("location_of_client.json",
               scopes = c("https://www.googleapis.com/auth/userinfo.email",
                          "https://www.googleapis.com/auth/userinfo.profile"))

gar_auth()

## default is user logged in
user <- get_user_info()

the_list <- whitelist(user, c("your@email.com", "another@email.com", "yet@anotheremail.com"))

if(the_list){
  message("You are on the list.")
} else {
  message("If you're not on the list, you're not getting in.")
}

About

Authentication and identifying Google users using Google+ API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 51.4%
  • Shell 18.9%
  • Rust 13.0%
  • JavaScript 8.4%
  • HTML 5.5%
  • R 2.8%