HIi team, Greetings to all, Actually I wanted to k...
# ory-selfhosting
b
HIi team, Greetings to all, Actually I wanted to kow How can we implement singin with google or social media with oAuth in ory.sh I have implemented in teh custom sdk given ory.sh but actually not able to figure it out how to implement same with custom Nest js backend is there any oryCient I can do it? Can anyone help me with this ? Below is the demo code that I have implemented for ory.sh with Nest js for signin with google.
Copy code
import { Controller, Get, Post, Body } from '@nestjs/common';
import axios from 'axios'; // For making HTTP requests

@Controller('auth')
export class AuthController {
  private readonly googleAuthEndpoint = '<https://www.googleapis.com/oauth2/v3/tokeninfo>';

  constructor(private readonly oryClient: OryClient) {} // Initialize your ORY client

  @Post('google-signin')
  async googleSignIn(@Body() { idToken, flowId }: { idToken: string; flowId: string }) {
    try {
      // Verify Google ID Token
      const { data } = await axios.get(`${this.googleAuthEndpoint}?id_token=${idToken}`);
      
      if (data) {
        // Create payload for ORY Hydra updateRegistrationFlow
        const body = {
          idToken,
          method: 'oidc',
          provider: 'google',
        };

        // Submit the updateRegistrationFlow endpoint with the payload
        await this.oryClient.getFrontendApi().updateRegistrationFlow({
          flow: flowId,
          updateRegistrationFlowBody: {
            oneOf: { value1: body },
          },
        });

        return { success: true, message: 'Google sign-in successful' };
      }
    } catch (error) {
      console.error('Google sign-in error:', error.message);
      return { success: false, message: 'Error signing in with Google' };
    }
  }
}
Please if anyone can help me with this it will be a great help thanks to you all, Warm Regards, Deepak A.M Yadav