Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from wassimk/wm/allow-state-param
Browse files Browse the repository at this point in the history
feat: allow using a state parameter in the authorization flow
  • Loading branch information
seven1m authored Apr 6, 2021
2 parents b482c5a + 6353fe4 commit a3b1be4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/mailchimp3/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ def initialize
)
end

def authorize_url(redirect_uri:)
@oauth.auth_code.authorize_url(redirect_uri: redirect_uri)
def authorize_url(redirect_uri:, state: nil)
params = {
redirect_uri: redirect_uri,
state: state,
}.compact

@oauth.auth_code.authorize_url(params)
end

def complete_auth(code, redirect_uri:)
Expand Down
8 changes: 8 additions & 0 deletions spec/mailchimp3/oauth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
)
expect(url).to eq('https://login.mailchimp.com/oauth2/authorize?client_id=foo&redirect_uri=http%3A%2F%2Fexample.com%2Foauth%2Fcallback&response_type=code')
end

it 'passes through an optional state param' do
url = subject.authorize_url(
redirect_uri: 'http://example.com/oauth/callback',
state: "123456"
)
expect(url).to eq('https://login.mailchimp.com/oauth2/authorize?client_id=foo&redirect_uri=http%3A%2F%2Fexample.com%2Foauth%2Fcallback&response_type=code&state=123456')
end
end

describe '#complete_auth' do
Expand Down

0 comments on commit a3b1be4

Please sign in to comment.