From 65fbfacd4b5313fce8473f98cf30c4e919e02323 Mon Sep 17 00:00:00 2001 From: Nuno Correia Date: Thu, 10 Nov 2022 21:04:47 +0000 Subject: [PATCH] add possibility to use sso with user id instead of email --- CHANGELOG.md | 5 ++++- Gemfile.lock | 2 +- README.md | 11 ++++++----- lib/learn_worlds/resources/single_sign_on_resource.rb | 4 ++++ lib/learn_worlds/version.rb | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8cc9ee..f3181a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 ) - diff --git a/Gemfile.lock b/Gemfile.lock index e83ef70..a1fc80f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - learnworlds (0.2.1) + learnworlds (0.2.2) faraday (~> 2.3) GEM diff --git a/README.md b/README.md index 18a5b44..f5ed8ff 100644 --- a/README.md +++ b/README.md @@ -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( @@ -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. @@ -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") } @@ -97,8 +97,9 @@ client.user.detach_tags(user_id: 'user_id', tags: ['tag1', 'tag2']) client.sso.redirect(email: 'test@test.com', redirect_to 'xyz.learnworlds.com/courses') -``` +client.sso.redirect_with_id(user_id: 'learnworlds_user_id', redirect_to 'xyz.learnworlds.com/courses') +``` ## Development diff --git a/lib/learn_worlds/resources/single_sign_on_resource.rb b/lib/learn_worlds/resources/single_sign_on_resource.rb index bed8def..5a500be 100644 --- a/lib/learn_worlds/resources/single_sign_on_resource.rb +++ b/lib/learn_worlds/resources/single_sign_on_resource.rb @@ -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 diff --git a/lib/learn_worlds/version.rb b/lib/learn_worlds/version.rb index 2a6cfa4..d01708c 100644 --- a/lib/learn_worlds/version.rb +++ b/lib/learn_worlds/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LearnWorlds - VERSION = "0.2.1" + VERSION = "0.2.2" end