-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoauth.R
57 lines (50 loc) · 1.81 KB
/
oauth.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# ---------------------------- OAuth setup ---------------------------------- #
# Synapse REST API docs:
# https://rest-docs.synapse.org/rest/#org.sagebionetworks.auth.OpenIDConnectController
DEBUG = Sys.getenv('DEBUG')
CLIENT_ID = NULL
CLIENT_SECRET = NULL
if (DEBUG){
# Local testing
APP_URL = Sys.getenv('APP_URL_LOCAL')
CLIENT_ID = Sys.getenv('CLIENT_ID_LOCAL')
CLIENT_SECRET = Sys.getenv('CLIENT_SECRET_LOCAL')
} else{
# Deployed
APP_URL = Sys.getenv('APP_URL')
CLIENT_ID = Sys.getenv('CLIENT_ID')
CLIENT_SECRET = Sys.getenv('CLIENT_SECRET')
}
if (is.null(CLIENT_ID)) stop('Missing CLIENT_ID. Did you forget to dencrypt .Renviron?')
if (is.null(CLIENT_SECRET)) stop('Missing CLIENT_SECRET. Did you forget to dencrypt .Renviron?')
# Create the OAuth app
APP <- oauth_app('Predictive BioAnalytics - Wyss',
key = CLIENT_ID,
secret = CLIENT_SECRET,
redirect_uri = APP_URL)
# These are the user info details ('claims') requested from Synapse:
claims <- list(
family_name = NULL,
given_name = NULL,
email = NULL,
email_verified = NULL,
userid = NULL,
orcid = NULL,
is_certified = NULL,
is_validated = NULL,
validated_given_name = NULL,
validated_family_name = NULL,
validated_location = NULL,
validated_email = NULL,
validated_company = NULL,
validated_at = NULL,
validated_orcid = NULL,
company = NULL
)
claimsParam <- toJSON(list(id_token = claims,
userinfo = claims))
# Synapse uses the OpenID Connect services to implement OAuth 2.0
API <- oauth_endpoint(authorize = paste0('https://signin.synapse.org?claims=', claimsParam),
access = 'https://repo-prod.prod.sagebase.org/auth/v1/oauth2/token')
# The 'openid' scope is required by the protocol for retrieving user information
SCOPE <- 'openid'