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

OpenAPI: login logout #4220

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 11 additions & 6 deletions api/login_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging

import google.oauth2.id_token
import werkzeug.exceptions
from chromestatus_openapi.models import SignInRequest
from google.auth.transport import requests

from framework import basehandlers
from framework import users
import settings
from framework import basehandlers, users


class LoginAPI(basehandlers.APIHandler):
Expand All @@ -31,8 +30,14 @@ def do_get(self, **kwargs):
self.abort(405, valid_methods=['POST'])

def do_post(self, **kwargs):
token = self.get_param('credential')
message = "Unable to Authenticate. Please sign in again."
try:
request = SignInRequest.from_dict(self.request.json)
token = request.credential
if not token:
raise werkzeug.exceptions.BadRequest(description="Missing required field 'credential'")
message = "Unable to Authenticate. Please sign in again."
except ValueError:
message = "Invalid Request"

try:
idinfo = google.oauth2.id_token.verify_oauth2_token(
Expand Down
10 changes: 4 additions & 6 deletions api/origin_trials_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from base64 import b64decode

import flask
import json5
import logging
import requests
import validators
from base64 import b64decode

from framework import basehandlers
from framework import origin_trials_client
from framework import basehandlers, origin_trials_client, permissions
from internals import notifier_helpers
from framework import permissions
from internals.core_enums import OT_READY_FOR_CREATION
from internals.core_models import FeatureEntry, Stage
from internals.review_models import Gate, Vote


WEBFEATURE_FILE_URL = 'https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom?format=TEXT'
ENABLED_FEATURES_FILE_URL = 'https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/platform/runtime_enabled_features.json5?format=TEXT'
GRACE_PERIOD_FILE = 'https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/common/origin_trials/manual_completion_origin_trial_features.cc?format=TEXT'
Expand Down
2 changes: 2 additions & 0 deletions gen/js/chromestatus-openapi/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ src/models/OwnersAndSubscribersOfComponent.ts
src/models/PatchCommentRequest.ts
src/models/PermissionsResponse.ts
src/models/PostIntentRequest.ts
src/models/RejectUnneededGetRequest.ts
src/models/ReviewLatency.ts
src/models/SignInRequest.ts
src/models/SpecMentor.ts
src/models/SuccessMessage.ts
src/models/TokenRefreshResponse.ts
Expand Down
192 changes: 184 additions & 8 deletions gen/js/chromestatus-openapi/src/apis/DefaultApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ import type {
PatchCommentRequest,
PermissionsResponse,
PostIntentRequest,
RejectUnneededGetRequest,
ReviewLatency,
SignInRequest,
SpecMentor,
SuccessMessage,
TokenRefreshResponse,
} from '../models/index';
import {
AccountResponseFromJSON,
Expand Down Expand Up @@ -84,14 +85,16 @@ import {
PermissionsResponseToJSON,
PostIntentRequestFromJSON,
PostIntentRequestToJSON,
RejectUnneededGetRequestFromJSON,
RejectUnneededGetRequestToJSON,
ReviewLatencyFromJSON,
ReviewLatencyToJSON,
SignInRequestFromJSON,
SignInRequestToJSON,
SpecMentorFromJSON,
SpecMentorToJSON,
SuccessMessageFromJSON,
SuccessMessageToJSON,
TokenRefreshResponseFromJSON,
TokenRefreshResponseToJSON,
} from '../models/index';

export interface AddFeatureCommentRequest {
Expand All @@ -111,6 +114,10 @@ export interface AddUserToComponentRequest {
componentUsersRequest?: ComponentUsersRequest;
}

export interface AuthenticateUserRequest {
signInRequest: SignInRequest;
}

export interface CreateAccountOperationRequest {
createAccountRequest?: CreateAccountRequest;
}
Expand Down Expand Up @@ -241,6 +248,21 @@ export interface DefaultApiInterface {
*/
addUserToComponent(requestParameters: AddUserToComponentRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;

/**
*
* @summary Authenticate user with Google Sign-In
* @param {SignInRequest} signInRequest
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DefaultApiInterface
*/
authenticateUserRaw(requestParameters: AuthenticateUserRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<SuccessMessage>>;

/**
* Authenticate user with Google Sign-In
*/
authenticateUser(requestParameters: AuthenticateUserRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<SuccessMessage>;

/**
*
* @summary Create a new account
Expand Down Expand Up @@ -484,6 +506,20 @@ export interface DefaultApiInterface {
*/
listSpecMentors(requestParameters: ListSpecMentorsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<SpecMentor>>;

/**
*
* @summary Log out the current user
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DefaultApiInterface
*/
logoutUserRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<SuccessMessage>>;

/**
* Log out the current user
*/
logoutUser(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<SuccessMessage>;

/**
*
* @summary Submit an intent to be posted on blink-dev
Expand All @@ -509,12 +545,40 @@ export interface DefaultApiInterface {
* @throws {RequiredError}
* @memberof DefaultApiInterface
*/
refreshTokenRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<TokenRefreshResponse>>;
refreshTokenRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<ReviewLatency>>>;

/**
* Refresh the XSRF token
*/
refreshToken(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenRefreshResponse>;
refreshToken(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<ReviewLatency>>;

/**
*
* @summary reject unneeded GET request without triggering Error Reporting
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DefaultApiInterface
*/
rejectGetRequestsLoginRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>>;

/**
* reject unneeded GET request without triggering Error Reporting
*/
rejectGetRequestsLogin(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;

/**
*
* @summary reject unneeded GET request without triggering Error Reporting
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof DefaultApiInterface
*/
rejectGetRequestsLogoutRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>>;

/**
* reject unneeded GET request without triggering Error Reporting
*/
rejectGetRequestsLogout(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void>;

/**
*
Expand Down Expand Up @@ -681,6 +745,42 @@ export class DefaultApi extends runtime.BaseAPI implements DefaultApiInterface {
await this.addUserToComponentRaw(requestParameters, initOverrides);
}

/**
* Authenticate user with Google Sign-In
*/
async authenticateUserRaw(requestParameters: AuthenticateUserRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<SuccessMessage>> {
if (requestParameters['signInRequest'] == null) {
throw new runtime.RequiredError(
'signInRequest',
'Required parameter "signInRequest" was null or undefined when calling authenticateUser().'
);
}

const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

headerParameters['Content-Type'] = 'application/json';

const response = await this.request({
path: `/login`,
method: 'POST',
headers: headerParameters,
query: queryParameters,
body: SignInRequestToJSON(requestParameters['signInRequest']),
}, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => SuccessMessageFromJSON(jsonValue));
}

/**
* Authenticate user with Google Sign-In
*/
async authenticateUser(requestParameters: AuthenticateUserRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<SuccessMessage> {
const response = await this.authenticateUserRaw(requestParameters, initOverrides);
return await response.value();
}

/**
* Create a new account
*/
Expand Down Expand Up @@ -1220,6 +1320,32 @@ export class DefaultApi extends runtime.BaseAPI implements DefaultApiInterface {
return await response.value();
}

/**
* Log out the current user
*/
async logoutUserRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<SuccessMessage>> {
const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

const response = await this.request({
path: `/logout`,
method: 'POST',
headers: headerParameters,
query: queryParameters,
}, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => SuccessMessageFromJSON(jsonValue));
}

/**
* Log out the current user
*/
async logoutUser(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<SuccessMessage> {
const response = await this.logoutUserRaw(initOverrides);
return await response.value();
}

/**
* Submit an intent to be posted on blink-dev
*/
Expand Down Expand Up @@ -1273,7 +1399,7 @@ export class DefaultApi extends runtime.BaseAPI implements DefaultApiInterface {
/**
* Refresh the XSRF token
*/
async refreshTokenRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<TokenRefreshResponse>> {
async refreshTokenRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<ReviewLatency>>> {
const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};
Expand All @@ -1285,17 +1411,67 @@ export class DefaultApi extends runtime.BaseAPI implements DefaultApiInterface {
query: queryParameters,
}, initOverrides);

return new runtime.JSONApiResponse(response, (jsonValue) => TokenRefreshResponseFromJSON(jsonValue));
return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(ReviewLatencyFromJSON));
}

/**
* Refresh the XSRF token
*/
async refreshToken(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenRefreshResponse> {
async refreshToken(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<ReviewLatency>> {
const response = await this.refreshTokenRaw(initOverrides);
return await response.value();
}

/**
* reject unneeded GET request without triggering Error Reporting
*/
async rejectGetRequestsLoginRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

const response = await this.request({
path: `/login`,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);

return new runtime.VoidApiResponse(response);
}

/**
* reject unneeded GET request without triggering Error Reporting
*/
async rejectGetRequestsLogin(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
await this.rejectGetRequestsLoginRaw(initOverrides);
}

/**
* reject unneeded GET request without triggering Error Reporting
*/
async rejectGetRequestsLogoutRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
const queryParameters: any = {};

const headerParameters: runtime.HTTPHeaders = {};

const response = await this.request({
path: `/logout`,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);

return new runtime.VoidApiResponse(response);
}

/**
* reject unneeded GET request without triggering Error Reporting
*/
async rejectGetRequestsLogout(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
await this.rejectGetRequestsLogoutRaw(initOverrides);
}

/**
* Remove a user from a component
*/
Expand Down
Loading