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

feat: support for multiple business setup documented #347

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
39 changes: 34 additions & 5 deletions src/content/docs/developer-tools/sdks/backend/ruby-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ The `KINDE_MANAGEMENT_CLIENT_ID` and the `KINDE_MANAGEMENT_CLIENT_SECRET` can be
```ruby
KindeSdk.client_credentials_access(
client_id: ENV["KINDE_MANAGEMENT_CLIENT_ID"],
client_secret: ENV["KINDE_MANAGEMENT_CLIENT_SECRET"]
# client_id: # default to @config.client_id
client_secret: ENV["KINDE_MANAGEMENT_CLIENT_SECRET"],
# client_secret: # default to @config.client_secret,
# audience: # default to "#{@config.domain}/api",
# domain: # default to @config.domain
)
```

Expand All @@ -129,7 +133,13 @@ KindeSdk.client_credentials_access(
The Kinde client provides methods for easy login and registration. For this, you need to acquire an auth URL by calling:

```ruby
KindeSdk.auth_url
KindeSdk.auth_url(
# client_id: # default to @config.client_id,
# client_secret: # default to @config.client_secret,
# domain: # default to @config.domain,
# redirect_uri: # default to @config.callback_url,
**kwargs
)
{
url: "https://<domain>/oauth2/auth?client_id=<client_id>&code_challenge=<generated code>&code_challenge_method=S256&redirect_uri=<redirect_uri>&response_type=code&scope=openid+offline+email+profile&state=<random string>",
code_verifier: "<challenge verifier>"
Expand Down Expand Up @@ -165,7 +175,14 @@ Callback is triggered in the body with the code. Use the whole `params` object o
Next, exchange access and refresh tokens. You will receive `code` as the parameter in the callback endpoint, and `code_verifier` (if PKCE enabled) as per the previous step.

```ruby
KindeApi.fetch_tokens(code, code_verifier: code_verifier)
KindeApi.fetch_tokens(
params_or_code,
# client_id: # default to @config.client_id,
# client_secret: # default to @config.client_secret,
# domain: # default to @config.domain,
# code_verifier: # default to nil,
# redirect_uri: # default to @config.callback_url
)
{"access_token"=>"eyJhbGciOiJSUzI1NiIsIm...",
"expires_in"=>86399,
"id_token"=>"eyJhbGciOiJSUz",
Expand Down Expand Up @@ -494,8 +511,20 @@ client.organizations.add_organization_users(code: "org_1111", users: ["kp:12311.
For proper refreshing you'll need to use `access_token`, `refresh_token` and probably `expires_in` if you want to know if your access token is still active. Use these two methods to work with refreshing:

```ruby
KindeApi.token_expired?(session[:kinde_auth]) # => false
KindeApi.refresh_token(session[:kinde_auth]) # => {"access_token" => "qwe...", "refresh_token" => "fqw...", .....}
KindeApi.token_expired?(
session[:kinde_auth],
# client_id: # default to @config.client_id,
# client_secret: # default to @config.client_secret,
# audience: # default to "#{@config.domain}/api",
# domain: # default to @config.domain
) # => false
KindeApi.refresh_token(
session[:kinde_auth],
# client_id: # default to @config.client_id,
# client_secret: # default to @config.client_secret,
# audience: # default to "#{@config.domain}/api",
# domain: # default to @config.domain
) # => {"access_token" => "qwe...", "refresh_token" => "fqw...", .....}

```

Expand Down