Skip to content

Commit

Permalink
add possibility to use sso with user id instead of email
Browse files Browse the repository at this point in the history
  • Loading branch information
lopesrb committed Nov 10, 2022
1 parent 472a080 commit 65fbfac
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

## [0.2.2] - 2022-08-09

- Add possibility to sso with user id instead of email

## [0.2.1] - 2022-08-09

- Add attach and detach methods to the user resource
Expand Down Expand Up @@ -27,4 +31,3 @@
- Initial release
- Adds a basic structure to aid future developments
- Adds methods to interact with the user resource ( list, create, update, find and enroll )

2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
learnworlds (0.2.1)
learnworlds (0.2.2)
faraday (~> 2.3)

GEM
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ If bundler is not being used to manage dependencies, install the gem by executin

### Authentication with Client Credentials grant

To authenticate with client credentials grant you need to
To authenticate with client credentials grant you need to

```ruby
client = LearnWorlds::Client.new(
Expand All @@ -42,13 +42,13 @@ client = LearnWorlds::Client.new(

you can also save some lines of code if you set the folloing env vars `LEARN_WORLDS_CLIENT_ID`, `LEARN_WORLDS_CLIENT_SECRET`, `LEARN_WORLDS_BASE_URL`

Once that is done, you can initialize the client with
Once that is done, you can initialize the client with

```ruby
client = LearnWorlds::Client.new
```

Everytime you call `authenticate('client_credentials')` a new request will be made to Learn Worlds.
Everytime you call `authenticate('client_credentials')` a new request will be made to Learn Worlds.
If you want to avoid that you can define custom getters and setters for the access token via the configuration.

You can use that to add logic to persist or get the access token on your side and you can also add some logic to verify if the access token is still valid.
Expand All @@ -57,7 +57,7 @@ For example:

```ruby
LearnWorlds.configure do |config|

# return nil if access_token is invalid and you want to proceed with the authentication process
config.retrieve_access_token_method = ->() { Rails.cache.fetch("learnworlds_access_token") }

Expand Down Expand Up @@ -97,8 +97,9 @@ client.user.detach_tags(user_id: 'user_id', tags: ['tag1', 'tag2'])

client.sso.redirect(email: '[email protected]', redirect_to 'xyz.learnworlds.com/courses')

```
client.sso.redirect_with_id(user_id: 'learnworlds_user_id', redirect_to 'xyz.learnworlds.com/courses')

```

## Development

Expand Down
4 changes: 4 additions & 0 deletions lib/learn_worlds/resources/single_sign_on_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ class SingleSignOnResource < Resource
def redirect(email:, redirect_to:)
post_request(SSO_ENDPOINT, { email: email, redirectUrl: redirect_to }).body['url']
end

def redirect_with_id(user_id:, redirect_to:)
post_request(SSO_ENDPOINT, { user_id: user_id, redirectUrl: redirect_to }).body['url']
end
end
end
2 changes: 1 addition & 1 deletion lib/learn_worlds/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module LearnWorlds
VERSION = "0.2.1"
VERSION = "0.2.2"
end

0 comments on commit 65fbfac

Please sign in to comment.