32
32
# ' }
33
33
# ' @export
34
34
auth0_ui <- function (ui , info ) {
35
- if (missing(info )) info <- auth0_info()
36
- function (req ) {
37
- verify <- has_auth_code(shiny :: parseQueryString(req $ QUERY_STRING ), info $ state )
38
- if (! verify ) {
39
- if (grepl(" error=unauthorized" , req $ QUERY_STRING )) {
40
- redirect <- sprintf(" location.replace(\" %s\" );" , logout_url())
41
- shiny :: tags $ script(shiny :: HTML(redirect ))
42
- } else {
35
+ disable <- getOption(" auth0_disable" )
36
+ if (! is.null(disable ) && disable ) {
37
+ ui
38
+ } else {
39
+ if (missing(info )) info <- auth0_info()
40
+ function (req ) {
41
+ verify <- has_auth_code(shiny :: parseQueryString(req $ QUERY_STRING ), info $ state )
42
+ if (! verify ) {
43
+ if (grepl(" error=unauthorized" , req $ QUERY_STRING )) {
44
+ redirect <- sprintf(" location.replace(\" %s\" );" , logout_url())
45
+ shiny :: tags $ script(shiny :: HTML(redirect ))
46
+ } else {
43
47
44
- params <- shiny :: parseQueryString(req $ QUERY_STRING )
45
- params $ code <- NULL
46
- params $ state <- NULL
48
+ params <- shiny :: parseQueryString(req $ QUERY_STRING )
49
+ params $ code <- NULL
50
+ params $ state <- NULL
47
51
48
- query <- paste0(" /?" , paste(
49
- mapply(paste , names(params ), params , MoreArgs = list (sep = " =" )),
50
- collapse = " &" ))
51
- if (! is.null(info $ remote_url ) && info $ remote_url != " " && ! getOption(" auth0_local" )) {
52
- redirect_uri <- info $ remote_url
53
- } else {
54
- if (grepl(" 127.0.0.1" , req $ HTTP_HOST )) {
55
- redirect_uri <- paste0(" http://" , gsub(" 127.0.0.1" , " localhost" , req $ HTTP_HOST , query ))
52
+ query <- paste0(" /?" , paste(
53
+ mapply(paste , names(params ), params , MoreArgs = list (sep = " =" )),
54
+ collapse = " &" ))
55
+ if (! is.null(info $ remote_url ) && info $ remote_url != " " && ! getOption(" auth0_local" )) {
56
+ redirect_uri <- info $ remote_url
56
57
} else {
57
- redirect_uri <- paste0(" http://" , req $ HTTP_HOST , query )
58
+ if (grepl(" 127.0.0.1" , req $ HTTP_HOST )) {
59
+ redirect_uri <- paste0(" http://" , gsub(" 127.0.0.1" , " localhost" , req $ HTTP_HOST , query ))
60
+ } else {
61
+ redirect_uri <- paste0(" http://" , req $ HTTP_HOST , query )
62
+ }
58
63
}
59
- }
60
- redirect_uri <<- redirect_uri
64
+ redirect_uri <<- redirect_uri
61
65
62
- query_extra <- if (is.null(info $ audience )) list () else list (audience = info $ audience )
63
- url <- httr :: oauth2.0_authorize_url(
64
- info $ api , info $ app(redirect_uri ), scope = info $ scope , state = info $ state ,
65
- query_extra = query_extra
66
- )
67
- redirect <- sprintf(" location.replace(\" %s\" );" , url )
68
- shiny :: tags $ script(shiny :: HTML(redirect ))
69
- }
70
- } else {
71
- if (is.function(ui )) {
72
- ui(req )
66
+ query_extra <- if (is.null(info $ audience )) list () else list (audience = info $ audience )
67
+ url <- httr :: oauth2.0_authorize_url(
68
+ info $ api , info $ app(redirect_uri ), scope = info $ scope , state = info $ state ,
69
+ query_extra = query_extra
70
+ )
71
+ redirect <- sprintf(" location.replace(\" %s\" );" , url )
72
+ shiny :: tags $ script(shiny :: HTML(redirect ))
73
+ }
73
74
} else {
74
- ui
75
+ if (is.function(ui )) {
76
+ ui(req )
77
+ } else {
78
+ ui
79
+ }
75
80
}
76
81
}
77
82
}
@@ -85,11 +90,16 @@ auth0_ui <- function(ui, info) {
85
90
# '
86
91
# ' @export
87
92
auth0_server <- function (server , info ) {
88
- if (missing(info )) info <- auth0_info()
89
- function (input , output , session ) {
90
- shiny :: isolate(auth0_server_verify(session , info $ app , info $ api , info $ state ))
91
- shiny :: observeEvent(input [[" ._auth0logout_" ]], logout())
92
- server(input , output , session )
93
+ disable <- getOption(" auth0_disable" )
94
+ if (! is.null(disable ) && disable ) {
95
+ server
96
+ } else {
97
+ if (missing(info )) info <- auth0_info()
98
+ function (input , output , session ) {
99
+ shiny :: isolate(auth0_server_verify(session , info $ app , info $ api , info $ state ))
100
+ shiny :: observeEvent(input [[" ._auth0logout_" ]], logout())
101
+ server(input , output , session )
102
+ }
93
103
}
94
104
}
95
105
0 commit comments