Skip to content

Commit

Permalink
TSDK-366 - Ruby SDK Hosted Authentication missing optional parameters (
Browse files Browse the repository at this point in the history
…#374)

Hosted Authentication method was missing the provider and redirect_on_error params
  • Loading branch information
kraju3 authored Jul 26, 2022
1 parent 58b9fed commit 03356df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/nylas/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ def authenticate(name:, email_address:, provider:, settings:, reauth_account_id:
)
end

def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil)
def authentication_url(redirect_uri:, scopes:, response_type: "code", login_hint: nil, state: nil,
provider: nil, redirect_on_error: nil)
params = {
client_id: app_id,
redirect_uri: redirect_uri,
response_type: response_type,
login_hint: login_hint
}

params[:state] = state if state
params[:scopes] = scopes.join(",") if scopes
params[:provider] = provider if provider
params[:redirect_on_error] = redirect_on_error if redirect_on_error

"#{api_server}/oauth/authorize?#{URI.encode_www_form(params)}"
end
Expand Down
26 changes: 26 additions & 0 deletions spec/nylas/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@
end
end

context "with required and optional parameters" do
it "returns url for hosted_authentication with optional parameters" do
api = described_class.new(app_id: "2454354")

hosted_auth_url = api.authentication_url(
redirect_uri: "http://example.com",
scopes: %w[email calendar],
login_hint: "[email protected]",
state: "some-state",
provider: "gmail",
redirect_on_error: true
)

expected_url = "https://api.nylas.com/oauth/authorize"\
"?client_id=2454354"\
"&redirect_uri=http%3A%2F%2Fexample.com"\
"&response_type=code"\
"&login_hint=email%40example.com"\
"&state=some-state"\
"&scopes=email%2Ccalendar"\
"&provider=gmail"\
"&redirect_on_error=true"
expect(hosted_auth_url).to eq expected_url
end
end

context "when required parameter are missing" do
it "throws argument error if redirect uri is mising" do
api = described_class.new(app_id: "2454354")
Expand Down

0 comments on commit 03356df

Please sign in to comment.