Skip to content

Commit

Permalink
Merge pull request passportxyz#734 from gitcoinco/google_abstraction
Browse files Browse the repository at this point in the history
feat(google): this implements google abstraction
  • Loading branch information
nutrina authored Nov 18, 2022
2 parents bc7bb02 + d03f7fe commit a8df157
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 281 deletions.
2 changes: 2 additions & 0 deletions app/.env-example.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# .env
NEXT_PUBLIC_PASSPORT_GOOGLE_CLIENT_ID=MY-APP-ID.apps.googleusercontent.com
NEXT_PUBLIC_PASSPORT_GOOGLE_CALLBACK=http://localhost:3000/

NEXT_PUBLIC_PASSPORT_TWITTER_CLIENT_ID=ABC123456789
NEXT_PUBLIC_PASSPORT_TWITTER_CALLBACK=http://localhost:3000/
NEXT_PUBLIC_PASSPORT_FACEBOOK_APP_ID=123456789
Expand Down
11 changes: 10 additions & 1 deletion app/components/CardListV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Linkedin,
GTC,
GtcStaking,
Google,
} from "@gitcoin/passport-platforms";

// --- Components
Expand Down Expand Up @@ -82,7 +83,7 @@ providers.set("Github", {
providers.set("Gitcoin", {
platform: new Gitcoin.GitcoinPlatform({
clientId: process.env.NEXT_PUBLIC_PASSPORT_GITHUB_CLIENT_ID,
redirectUri: process.env.NEXT_PUBLIC_PASSPORT_GITHUB_CALLBACK,
redirectUri: process.env.NEXT_PUBLIC_PASSPORT_GOOGLE_CALLBACK,
}),
platFormGroupSpec: Gitcoin.GitcoinProviderConfig,
});
Expand Down Expand Up @@ -145,6 +146,14 @@ providers.set("GtcStaking", {
platFormGroupSpec: GtcStaking.GTCStakingProviderConfig,
});

providers.set("Google", {
platform: new Google.GooglePlatform({
clientId: process.env.NEXT_PUBLIC_PASSPORT_GOOGLE_CLIENT_ID,
redirectUri: process.env.NEXT_PUBLIC_PASSPORT_GOOGLE_CALLBACK,
}),
platFormGroupSpec: Google.GoogleProviderConfig,
});

export const CardList = ({ isLoading = false }: CardListProps): JSX.Element => {
const { allProvidersState } = useContext(CeramicContext);
const { isOpen, onOpen, onClose } = useDisclosure();
Expand Down
39 changes: 29 additions & 10 deletions database-client/__tests__/CeramicDatabase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import testnetAliases from "./integration-test-model-aliases.json";
import { TileDocument } from "@ceramicnetwork/stream-tile";
import { TileDoc } from "@glazed/did-datastore/dist/proxy";

import axios from "axios";

let testDID: DID;
let ceramicDatabase: CeramicDatabase;

Expand Down Expand Up @@ -87,12 +89,21 @@ describe("Verify Ceramic Database", () => {
id: "passport-id",
} as unknown as TileDoc;
});
let spyLoaderLoad = jest.spyOn(ceramicDatabase.loader, "load").mockImplementation(async (streamId) => {
// return new TileDocument(new SnapshotState(), );
return {
content: "Stamp Content for " + streamId,
} as any as TileDocument;
const spyLoadStreamReq = jest.spyOn(axios, "get").mockImplementation((url: string): Promise<{}> => {
return new Promise((resolve) => {
const urlSegments = url.split("/");
const streamId = urlSegments[urlSegments.length - 1];
resolve({
data: {
state: {
content: "Stamp Content for ceramic://" + streamId,
},
},
status: 200,
});
});
});

let spyPinAdd = jest.spyOn(ceramicDatabase.ceramicClient.pin, "add").mockImplementation(async (streamId) => {
// Nothing to do here
return;
Expand All @@ -103,7 +114,7 @@ describe("Verify Ceramic Database", () => {
// We do not expect to have any passport, hence `false` should be returned
expect(spyStoreGet).toBeCalledTimes(1);
expect(spyStoreGet).toBeCalledWith("Passport");
expect(spyLoaderLoad).toBeCalledTimes(3);
expect(spyLoadStreamReq).toBeCalledTimes(3);
expect(spyStoreGetRecordDocument).toBeCalledTimes(1);

// Ensure the document is pinned
Expand Down Expand Up @@ -164,17 +175,25 @@ describe("Verify Ceramic Database", () => {
id: "passport-id",
} as unknown as TileDoc;
});
let spyLoaderLoad = jest.spyOn(ceramicDatabase.loader, "load").mockImplementation(async (streamId) => {
const spyLoadStreamReq = jest.spyOn(axios, "get").mockImplementation((url: string): Promise<{}> => {
return new Promise((resolve, reject) => {
const urlSegments = url.split("/");
const streamId = urlSegments[urlSegments.length - 1];
if (numGoodStamps < maxGoodStamps) {
numGoodStamps += 1;
resolve({
content: "Stamp Content for " + streamId,
} as any as TileDocument);
data: {
state: {
content: "Stamp Content for ceramic://" + streamId,
},
},
status: 200,
});
}
reject("Error loading stamp!");
});
});

let spyPinAdd = jest.spyOn(ceramicDatabase.ceramicClient.pin, "add").mockImplementation(async (streamId) => {
// Nothing to do here
return;
Expand All @@ -185,7 +204,7 @@ describe("Verify Ceramic Database", () => {
// We do not expect to have any passport, hence `false` should be returned
expect(spyStoreGet).toBeCalledTimes(1);
expect(spyStoreGet).toBeCalledWith("Passport");
expect(spyLoaderLoad).toBeCalledTimes(3);
expect(spyLoadStreamReq).toBeCalledTimes(3);
expect(spyStoreGetRecordDocument).toBeCalledTimes(1);

// Ensure the document is pinned
Expand Down
3 changes: 1 addition & 2 deletions database-client/src/ceramicClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ export class CeramicDatabase implements DataStorageBase {
this.logger.error(
`Error when loading stamp with streamId ${streamIDs[idx]} for did ${this.did}:` + e.toString()
);
console.log(e);
return null;
throw e;
}
});

Expand Down
2 changes: 2 additions & 0 deletions iam/.env-example.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# .env
GOOGLE_CLIENT_ID=MY-APP-ID.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=MY_APP_SECRET
GOOGLE_CALLBACK=http://localhost:3000/

TWITTER_CLIENT_ID=MY-APP-ID-TWITTER
TWITTER_CLIENT_SECRET=MY_APP_SECRET
FACEBOOK_APP_ID=MY_APP_ID
Expand Down
84 changes: 0 additions & 84 deletions iam/__tests__/google.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions iam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { Providers } from "./utils/providers";

// ---- Identity Providers
import { SimpleProvider } from "./providers/simple";
import { GoogleProvider } from "./providers/google";

import {
Twitter,
Expand All @@ -61,6 +60,7 @@ import {
GTC,
GtcStaking,
Discord,
Google,
ClearText,
} from "@gitcoin/passport-platforms";

Expand All @@ -85,7 +85,7 @@ export const config: {
export const providers = new Providers([
// Example provider which verifies the payload when `payload.proofs.valid === "true"`
new SimpleProvider(),
new GoogleProvider(),
new Google.GoogleProvider(),
new Twitter.TwitterAuthProvider(),
new Ens.EnsProvider(),
new Poh.PohProvider(),
Expand Down
69 changes: 0 additions & 69 deletions iam/src/providers/google.ts

This file was deleted.

27 changes: 27 additions & 0 deletions platforms/src/Google/App-Bindings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// For details on the google oauth2 flow, please check the following ressources:
// - https://developers.google.com/identity/protocols/oauth2
// - https://developers.google.com/oauthplayground/

import { PlatformOptions } from "../types";
import { Platform } from "../utils/platform";

export class GooglePlatform extends Platform {
platformId = "Google";
path = "Google";
clientId: string = null;
redirectUri: string = null;

constructor(options: PlatformOptions = {}) {
super();
this.clientId = options.clientId as string;
this.redirectUri = options.redirectUri as string;
}

getOAuthUrl(state: string): Promise<string> {
return new Promise((resolve) => {
resolve(
`https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=${this.redirectUri}&prompt=consent&response_type=code&client_id=${this.clientId}&scope=email+profile&access_type=offline&state=${state}`
);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlatformSpec, PlatformGroupSpec } from "../../types";
import { PlatformSpec, PlatformGroupSpec } from "../types";

export const GooglePlatformDetails: PlatformSpec = {
icon: "./assets/googleStampIcon.svg",
Expand Down
Loading

0 comments on commit a8df157

Please sign in to comment.