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

fix: bitbucket gitlab impl and other fixes #642

Merged
merged 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
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
102 changes: 99 additions & 3 deletions lib/build/recipe/thirdparty/providers/bitbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,44 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
var __awaiter =
(this && this.__awaiter) ||
function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P
? value
: new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("./utils");
const custom_1 = __importDefault(require("./custom"));
function Bitbucket(input) {
if (input.config.name === undefined) {
Expand All @@ -30,10 +62,74 @@ function Bitbucket(input) {
if (input.config.tokenEndpoint === undefined) {
input.config.tokenEndpoint = "https://bitbucket.org/site/oauth2/access_token";
}
if (input.config.userInfoEndpoint === undefined) {
input.config.userInfoEndpoint = "https://api.bitbucket.org/2.0/user";
if (input.config.authorizationEndpointQueryParams === undefined) {
input.config.authorizationEndpointQueryParams = {
audience: "api.atlassian.com",
};
}
// TODO overrides and working of this
const oOverride = input.override;
input.override = function (originalImplementation) {
const oGetConfig = originalImplementation.getConfigForClientType;
originalImplementation.getConfigForClientType = function (input) {
return __awaiter(this, void 0, void 0, function* () {
const config = yield oGetConfig(input);
if (config.scope === undefined) {
config.scope = ["account", "email"];
}
return config;
});
};
originalImplementation.getUserInfo = function (input) {
return __awaiter(this, void 0, void 0, function* () {
const accessToken = input.oAuthTokens.access_token;
if (accessToken === undefined) {
throw new Error("Access token not found");
}
const headers = {
Authorization: `Bearer ${accessToken}`,
};
let rawUserInfoFromProvider = {
fromUserInfoAPI: {},
fromIdTokenPayload: {},
};
const userInfoFromAccessToken = yield utils_1.doGetRequest(
"https://api.bitbucket.org/2.0/user",
undefined,
headers
);
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken;
const userInfoFromEmail = yield utils_1.doGetRequest(
"https://api.bitbucket.org/2.0/user/emails",
undefined,
headers
);
rawUserInfoFromProvider.fromUserInfoAPI.email = userInfoFromEmail;
let email = undefined;
let isVerified = false;
for (const emailInfo of userInfoFromEmail.values) {
if (emailInfo.is_primary) {
email = emailInfo.email;
isVerified = emailInfo.is_confirmed;
}
}
return {
thirdPartyUserId: rawUserInfoFromProvider.fromUserInfoAPI.uuid,
email:
email === undefined
? undefined
: {
id: email,
isVerified,
},
rawUserInfoFromProvider,
};
});
};
if (oOverride !== undefined) {
originalImplementation = oOverride(originalImplementation);
}
return originalImplementation;
};
return custom_1.default(input);
}
exports.default = Bitbucket;
4 changes: 4 additions & 0 deletions lib/build/recipe/thirdparty/providers/configUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ function createProvider(input) {
return _1.ActiveDirectory(input);
} else if (input.config.thirdPartyId.startsWith("apple")) {
return _1.Apple(input);
} else if (input.config.thirdPartyId.startsWith("bitbucket")) {
return _1.Bitbucket(input);
} else if (input.config.thirdPartyId.startsWith("discord")) {
return _1.Discord(input);
} else if (input.config.thirdPartyId.startsWith("facebook")) {
return _1.Facebook(input);
} else if (input.config.thirdPartyId.startsWith("github")) {
return _1.Github(input);
} else if (input.config.thirdPartyId.startsWith("gitlab")) {
return _1.Gitlab(input);
} else if (input.config.thirdPartyId.startsWith("google-workspaces")) {
return _1.GoogleWorkspaces(input);
} else if (input.config.thirdPartyId.startsWith("google")) {
Expand Down
15 changes: 9 additions & 6 deletions lib/build/recipe/thirdparty/providers/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,15 @@ function getSupertokensUserInfoResultFromRawUserInfo(config, rawUserInfoResponse
}
function NewProvider(input) {
var _a;
input.config.userInfoMap = {
fromIdTokenPayload: Object.assign(
{ userId: "sub", email: "email", emailVerified: "email_verified" },
(_a = input.config.userInfoMap) === null || _a === void 0 ? void 0 : _a.fromIdTokenPayload
),
};
input.config.userInfoMap = Object.assign(
{
fromIdTokenPayload: Object.assign(
{ userId: "sub", email: "email", emailVerified: "email_verified" },
(_a = input.config.userInfoMap) === null || _a === void 0 ? void 0 : _a.fromIdTokenPayload
),
},
input.config.userInfoMap
);
if (input.config.generateFakeEmail === undefined) {
input.config.generateFakeEmail = function ({ thirdPartyUserId }) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/providers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getSupertokensUserInfoFromRawUserInfoResponseForGithub(rawUserInfoRespo
throw new Error("rawUserInfoResponse.fromUserInfoAPI is not available");
}
const result = {
thirdPartyUserId: rawUserInfoResponse.fromUserInfoAPI.user.id,
thirdPartyUserId: `${rawUserInfoResponse.fromUserInfoAPI.user.id}`,
rawUserInfoFromProvider: {
fromIdTokenPayload: {},
fromUserInfoAPI: {},
Expand Down
2 changes: 1 addition & 1 deletion lib/build/recipe/thirdparty/providers/gitlab.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// @ts-nocheck
import { TypeProvider, ProviderInput } from "../types";
export default function GitLab(input: ProviderInput): TypeProvider;
export default function Gitlab(input: ProviderInput): TypeProvider;
Loading
Loading