<@U04UQ68083H> I have a react application applicat...
# ory-copilot
s
@chilly-king-10285 I have a react application application & a backend written in goalng. The react app consumes apis from the backend. I want to introduce authentication using ory network which includes email + social sign in (google etc.). Note: All authentication requests should go through backend, no direct request to ory network should be made by client. How can i go about doing this?
c
A message from kapa.ai
To introduce authentication using Ory Network in your React and Go applications, you can follow these steps: 1. Create a Go application and secure it with Ory: - First, create a Go app by running the following commands:
Copy code
mkdir your-project        cd your-project        touch main.go handler.go middleware.go index.html        go mod init <http://github.com/<your-name>/your-project|github.com/<your-name>/your-project>
- Install the Ory SDK which allows you to interact with Ory APIs:
Copy code
go get -u <http://github.com/ory/client-go|github.com/ory/client-go>
- You can find more details [here](https://www.ory.sh/docs/getting-started/integrate-auth/go). 2. Integrate authentication into your React application: - Create a new React project:
Copy code
npx create-react-app my_project --template typescript        cd my_project
- Install the Ory SDK:
Copy code
npm i --save @ory/client
- You can find more details [here](https://www.ory.sh/docs/getting-started/integrate-auth/react). 3. Set up Ory Network: - Set up the Ory SDK URL which you can find in the [Ory Console](https://console.ory.sh/projects/current/developers/guides)
Copy code
export ORY_SDK_URL=https://{project.slug}.<http://projects.oryapis.com|projects.oryapis.com>
- Start the Ory Tunnel:
Copy code
npx @ory/cli tunnel --dev <http://localhost:3000>
- You can find more details [here](https://www.ory.sh/docs/getting-started/integrate-auth/react). 4. Go to production: - To connect the application to your Ory project, the app and Ory APIs must be available under the same common domain, for example
<https://ory.example.com>
and
<https://www.example.com>
. - Add a Custom Domain to your Ory Network project. - Use the configured custom domain in your SDK calls:
Copy code
// For Go      c := ory.NewConfiguration()        c.Servers = ory.ServerConfigurations{{URL: "<https://ory.example.org>"}}         // For React      var sdk = require("@ory/client")        var ory = new sdk.FrontendApi(        new sdk.Configuration({        basePath: "<https://ory.example.org>",        baseOptions: {        // Ensures that cookies are included in CORS requests:        withCredentials: true,        },        }),        )
- You can find more details [here](https://www.ory.sh/docs/getting-started/integrate-auth/go) and [here](https://www.ory.sh/docs/getting-started/integrate-auth/expressjs). Please note that all authentication requests should go through the backend, no direct request to Ory Network should be made by the client.
s
Ok, Looks good to me. As per understanding ory use cookie based authentication. So when a request is made from client side, i can verify the session using golang SDK. Do i need to take care of access & refresh token? As per my understaing oauth2 & openID works on JWT tokens? what happened to those tokens?