Skip to content

Commit

Permalink
refactor(console): update ruby guide (#6116)
Browse files Browse the repository at this point in the history
* refactor(console): update ruby guide

* refactor(console): support further readings

* refactor(console): reorg docs
  • Loading branch information
gao-sun authored Jun 27, 2024
1 parent 8fa4405 commit bd0487e
Show file tree
Hide file tree
Showing 26 changed files with 98 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import InlineNotification from '@/ds-components/InlineNotification';
import UriInputField from '@/mdx-components/UriInputField';

Before we dive into the details, here's a quick overview of the end-user experience. The sign-in process can be simplified as follows:

```mermaid
Expand All @@ -18,3 +21,15 @@ Regarding redirect-based sign-in:
To learn more about the rationale and benefits of redirect-based sign-in, see [Logto sign-in experience explained](https://docs.logto.io/docs/tutorials/get-started/sign-in-experience).

---

<InlineNotification>
In the following steps, we assume your app is running on <code>http://localhost:3000</code>.
</InlineNotification>

Now, let's enter your redirect URI. E.g. `http://localhost:3000/callback`.

<UriInputField name="redirectUris" />

Just like signing in, users should be redirected to Logto for signing out of the shared session. Once finished, it would be great to redirect the user back to your website. For example, add `http://localhost:3000` as the post sign-out redirect URI below.

<UriInputField name="postLogoutRedirectUris" />
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/m2m-general/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
description: 'Enables direct communication between machines.',
target: ApplicationType.MachineToMachine,
isFeatured: true,
fullGuide: {
title: 'Full machine-to-machine integration tutorial',
url: 'https://docs.logto.io/quick-starts/m2m',
},
fullGuide: 'm2m',
});

export default metadata;
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'kotlin',
path: 'android-sample-kotlin',
},
fullGuide: {
title: 'Full Android SDK tutorial',
url: 'https://docs.logto.io/quick-starts/android',
},
fullGuide: 'android',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/native-expo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'react-native',
path: 'packages/rn-sample',
},
fullGuide: {
title: 'Full Expo (React Native) guide',
url: 'https://docs.logto.io/quick-starts/expo',
},
fullGuide: 'expo',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/spa-angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'js',
path: 'packages/angular-sample',
},
fullGuide: {
title: 'Full Angular guide',
url: 'https://docs.logto.io/quick-starts/angular',
},
fullGuide: 'angular',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/spa-react/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
path: 'packages/react-sample',
},
isFeatured: true,
fullGuide: {
title: 'Full React SDK tutorial',
url: 'https://docs.logto.io/quick-starts/react',
},
fullGuide: 'react',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/spa-vanilla/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'js',
path: 'packages/browser-sample',
},
fullGuide: {
title: 'Full vanilla JS SDK tutorial',
url: 'https://docs.logto.io/quick-starts/vanilla-js',
},
fullGuide: 'vanilla-js',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/spa-vue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
path: 'packages/vue-sample',
},
isFeatured: true,
fullGuide: {
title: 'Full Vue SDK tutorial',
url: 'https://docs.logto.io/quick-starts/vue',
},
fullGuide: 'vue',
});

export default metadata;
11 changes: 7 additions & 4 deletions packages/console/src/assets/docs/guides/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ export type GuideMetadata = {
/** Indicate whether the application is for third-party use */
isThirdParty?: boolean;

/** The related complete guide for this guide which will be displayed in the 'Further readings' section. */
fullGuide?: {
/** The related complete guide url relative to the quick starts page (https://docs.logto.io/quick-starts). */
fullGuide?: string;

/** The related URLs to add to the further readings section. */
furtherReadings?: Array<{
title: string;
url: string;
};
url: URL;
}>;
};

/** The guide instance to build in the console. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'csharp',
path: '/',
},
fullGuide: {
title: 'Full .NET Core (Blazor Server) integration tutorial',
url: 'https://docs.logto.io/quick-starts/dotnet-core/blazor-server',
},
fullGuide: 'dotnet-core/blazor-server',
});

export default metadata;
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'csharp',
path: '/',
},
fullGuide: {
title: 'Full .NET Core (Blazor WASM) integration tutorial',
url: 'https://docs.logto.io/quick-starts/dotnet-core/blazor-wasm',
},
fullGuide: 'dotnet-core/blazor-wasm',
});

export default metadata;
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'csharp',
path: '/',
},
fullGuide: {
title: 'Full .NET Core (MVC) integration tutorial',
url: 'https://docs.logto.io/quick-starts/dotnet-core/mvc',
},
fullGuide: 'dotnet-core/mvc',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/web-express/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'js',
path: 'packages/express-sample',
},
fullGuide: {
title: 'Full Express SDK tutorial',
url: 'https://docs.logto.io/quick-starts/express',
},
fullGuide: 'express',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/web-go/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'go',
path: 'gin-sample',
},
fullGuide: {
title: 'Full Go SDK tutorial',
url: 'https://docs.logto.io/quick-starts/go',
},
fullGuide: 'go',
});

export default metadata;
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
path: 'packages/next-server-actions-sample',
},
isFeatured: true,
fullGuide: {
title: 'Full Next.js SDK tutorial',
url: 'https://docs.logto.io/sdk/next-app-router/',
},
fullGuide: 'next-app-router',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/web-next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'js',
path: 'packages/next-sample',
},
fullGuide: {
title: 'Full Next.js SDK tutorial',
url: 'https://docs.logto.io/quick-starts/next',
},
fullGuide: 'next',
});

export default metadata;
21 changes: 6 additions & 15 deletions packages/console/src/assets/docs/guides/web-nuxt/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import InlineNotification from '@/ds-components/InlineNotification';
import Steps from '@/mdx-components/Steps';
import Step from '@/mdx-components/Step';
import Checkpoint from '../../fragments/_checkpoint.md';
import SignInExplanation from '../../fragments/_sign_in_explanation.md';
import RedirectUris from '../../fragments/_redirect_uris.mdx';
import { generateStandardSecret } from '@logto/shared/universal';

export const cookieEncryptionKey = generateStandardSecret();
Expand Down Expand Up @@ -79,21 +79,12 @@ See [runtime config](https://nuxt.com/docs/guide/going-further/runtime-config) f

</Step>

<Step title="Configure your app">

<SignInExplanation />

<InlineNotification>
In the following steps, we assume your app is running on <code>http://localhost:3000</code>.
</InlineNotification>

Now, let's enter your redirect URI. E.g. `http://localhost:3000/callback`.

<UriInputField name="redirectUris" />

Just like signing in, users should be redirected to Logto for signing out of the shared session. Once finished, it would be great to redirect the user back to your website. For example, add `http://localhost:3000` as the post sign-out redirect URI below.
<Step
title="Configure redirect URIs"
subtitle="2 URIs"
>

<UriInputField name="postLogoutRedirectUris" />
<RedirectUris />

When registering `@logto/nuxt` module, it will do the following:

Expand Down
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/web-nuxt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'js',
path: 'packages/nuxt',
},
fullGuide: {
title: 'Full Nuxt guide',
url: 'https://docs.logto.io/quick-starts/nuxt',
},
fullGuide: 'nuxt',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/web-php/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'php',
path: 'samples',
},
fullGuide: {
title: 'Full PHP SDK tutorial',
url: 'https://docs.logto.io/quick-starts/php',
},
fullGuide: 'php',
});

export default metadata;
5 changes: 1 addition & 4 deletions packages/console/src/assets/docs/guides/web-python/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ const metadata: Readonly<GuideMetadata> = Object.freeze({
repo: 'python',
path: 'samples',
},
fullGuide: {
title: 'Full Python SDK tutorial',
url: 'https://docs.logto.io/quick-starts/python',
},
fullGuide: 'python',
});

export default metadata;
44 changes: 20 additions & 24 deletions packages/console/src/assets/docs/guides/web-ruby/README.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import UriInputField from '@/mdx-components/UriInputField';
import InlineNotification from '@/ds-components/InlineNotification';
import { generateStandardSecret } from '@logto/shared/universal';
import RedirectUris from '../../fragments/_redirect_uris.mdx';
import Checkpoint from '../../fragments/_checkpoint.md';
import Steps from '@/mdx-components/Steps';
import Step from '@/mdx-components/Step';

Expand Down Expand Up @@ -49,9 +51,8 @@ end`}

For instance, in a Rails controller, the code might look like this:

<Code className="language-ruby">
{`# app/controllers/sample_controller.rb
require "logto/client"
<Code title="app/controllers/sample_controller.rb" className="language-ruby">
{`require "logto/client"
class SampleController < ApplicationController
before_action :initialize_logto_client
Expand Down Expand Up @@ -81,13 +82,7 @@ end`}
subtitle="2 URIs"
>

First, let's enter your redirect URI. E.g. `http://localhost:3000/callback`. [Redirect URI](https://www.oauth.com/oauth2-servers/redirect-uris/) is an OAuth 2.0 concept which implies the location should redirect after authentication.

<UriInputField name="redirectUris" />

After signing out, it'll be great to redirect user back to your website. For example, add `http://localhost:3000` as the post sign-out redirect URI below.

<UriInputField name="postLogoutRedirectUris" />
<RedirectUris />

</Step>

Expand All @@ -100,18 +95,17 @@ After signing out, it'll be great to redirect user back to your website. For exa
Since the redirect URI has been set to <code>{props.redirectUris[0] || 'http://localhost:3000/callback'}</code>, it needs to be handled it in our application. In a Rails controller, you can add the following code:
</p>

<Code className="language-ruby">
{`# app/controllers/sample_controller.rb
class SampleController < ApplicationController
<Code title="app/controllers/sample_controller.rb" className="language-ruby">
{`class SampleController < ApplicationController
def ${props.redirectUris[0]?.split('/').pop() || 'callback'}
@client.handle_sign_in_callback(url: request.original_url)
end
end`}
</Code>

And configure the route in `config/routes.rb`:
And configure the route:

<Code className="language-ruby">
<Code title="config/routes.rb" className="language-ruby">
{`Rails.application.routes.draw do
get "${new URL(props.redirectUris[0] || 'http://localhost:3000/callback').pathname}", to: "sample#${props.redirectUris[0]?.split('/').pop() || 'callback'}"
end`}
Expand All @@ -125,9 +119,8 @@ end`}

There are various ways to invoke sign-in and sign-out in your application. For example, you can implement two routes in your Rails application:

<Code className="language-ruby">
{`# app/controllers/sample_controller.rb
class SampleController < ApplicationController
<Code title="app/controllers/sample_controller.rb" className="language-ruby">
{`class SampleController < ApplicationController
def sign_in
@client.sign_in(redirect_uri: request.base_url + "${new URL(props.redirectUris[0] || 'http://localhost:3000/callback').pathname}")
end
Expand All @@ -140,8 +133,7 @@ class SampleController < ApplicationController
end`}
</Code>

```ruby
# config/routes.rb
```ruby title="config/routes.rb"
Rails.application.routes.draw do
get "/sign_in", to: "sample#sign_in"
get "/sign_out", to: "sample#sign_out"
Expand All @@ -152,8 +144,7 @@ end

Then you can create buttons or links in your views to trigger these actions. For example:

```erb
<!-- app/views/sample/index.html.erb -->
```erb title="app/views/sample/index.html.erb"
<% if @client.is_authenticated? %>
<a href="<%= sign_out_path %>">Sign out</a>
<% else %>
Expand All @@ -163,12 +154,17 @@ Then you can create buttons or links in your views to trigger these actions. For

</Step>

<Step title="Checkpoint: Test your app">

<Checkpoint />

</Step>

<Step title="Display user information">

To display the user's information, you can use the `@client.id_token_claims` method. For example, in a view:

```erb
<!-- app/views/sample/index.html.erb -->
```erb title="app/views/sample/index.html.erb"
<% if @client.is_authenticated? %>
<p>Welcome, <%= @client.id_token_claims["name"] %></p>
<% else %>
Expand Down
Loading

0 comments on commit bd0487e

Please sign in to comment.