Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to pass custom state in authentication URL #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Or install it yourself as:

### Configuration

`Bamboo::Configuration.redirect_url` must be set.
`BambooId::Configuration.redirect_url` must be set.

The following environment variables are also required:
- `BAMBOO_APPLICATION_KEY`
Expand All @@ -33,13 +33,20 @@ The following environment variables are also required:

To get the initial authorization URL, use `BambooId::Urls::AuthUrl.new(subdomain).to_s`

You can also pass an optional custom `state` attribute to this URL like this:

```ruby
state = "my_custom_state"
BambooId::Urls::AuthUrl.new(subdomain, state).to_s
```

In the callback controller, you can use `BambooId::ApiKeyFetcher` to get an API key
using the code passed to you like so:

```ruby
::BambooId::ApiKeyFetcher.new(
code: params[:code],
integration: current_company.user_management_integration
subdomain: subdomain,
).fetch
```

Expand Down
7 changes: 4 additions & 3 deletions lib/bamboo_id/urls/auth_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ class AuthUrl
include BambooUrl
include BaseAuthUrl

def initialize(subdomain)
def initialize(subdomain, state = nil)
self.subdomain = subdomain
self.state = state
end

private

attr_accessor :subdomain
attr_accessor :subdomain, :state

def additional_params
{
Expand All @@ -44,7 +45,7 @@ def redirect_uri
end

def state_code
StateCode.new(subdomain).to_s
state || StateCode.new(subdomain).to_s
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/bamboo_id/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BambooId
VERSION = "0.1.3"
VERSION = "0.1.4"
end