@@ -107,13 +107,11 @@ def globus
107107
108108 def orcid
109109 auth = request . env [ "omniauth.auth" ]
110+ omni_params = request . env [ "omniauth.params" ]
110111 omniauth = flash [ :omniauth ] || { }
111112
112113 if current_user . present?
113114 @user = current_user
114- @user . update ( orcid_expires_at : User . timestamp ( auth . credentials ) ,
115- orcid_token : auth . credentials . token )
116- flash [ :notice ] = "ORCID token successfully refreshed."
117115 else
118116 @user = User . from_omniauth ( auth , provider : "globus" )
119117 end
@@ -129,6 +127,13 @@ def orcid
129127 if @user . persisted?
130128 sign_in @user
131129
130+ # Refresh ORCID token if the flag isn't explicitly false
131+ if omni_params [ "fetch_token" ] != "false"
132+ @user . update ( orcid_expires_at : User . timestamp ( auth . credentials ) ,
133+ orcid_token : auth . credentials . token )
134+ flash [ :notice ] = "ORCID token successfully refreshed."
135+ end
136+
132137 cookies [ :_datacite ] = encode_cookie ( @user . jwt )
133138
134139 if stored_location_for ( :user ) == ENV [ "BLOG_URL" ] + "/admin/"
@@ -145,7 +150,13 @@ def orcid
145150
146151 netlify_response ( token : token , content : content )
147152 else
148- redirect_to stored_location_for ( :user ) || setting_path ( "me" )
153+
154+ # Redirect to Commons if the flag isn't explicitly false. Otherwise redirect to profile settings
155+ if omni_params [ "redirect_to_commons" ] != "false"
156+ redirect_to "#{ ENV [ 'COMMONS_URL' ] } /orcid.org/#{ current_user . orcid } "
157+ else
158+ redirect_to stored_location_for ( :user ) || setting_path ( "me" )
159+ end
149160 end
150161 else
151162 flash [ :alert ] = @user . errors . map { |k , v | "#{ k } : #{ v } " } . join ( "<br />" ) . html_safe || "Error signing in with #{ provider } "
0 commit comments