diff --git a/api/token_refresh_api.py b/api/token_refresh_api.py index 4b754c10..c9d247d6 100644 --- a/api/token_refresh_api.py +++ b/api/token_refresh_api.py @@ -15,6 +15,8 @@ import logging +from chromestatus_openapi.models import TokenRefreshResponse + from framework import basehandlers from framework import xsrf from framework import users @@ -41,9 +43,9 @@ class TokenRefreshAPI(basehandlers.APIHandler): """Refresh the session and return a new XSRF token for the current user.""" user = self.get_current_user() users.refresh_user_session() - result = { + result = TokenRefreshResponse.from_dict({ 'token': xsrf.generate_token(user.email()), 'token_expires_sec': xsrf.token_expires_sec(), - } + }) self._update_last_visit_field(user.email()) - return result + return result.to_dict() diff --git a/gen/js/chromestatus-openapi/.openapi-generator/FILES b/gen/js/chromestatus-openapi/.openapi-generator/FILES index e1d91c92..d105c6a1 100644 --- a/gen/js/chromestatus-openapi/.openapi-generator/FILES +++ b/gen/js/chromestatus-openapi/.openapi-generator/FILES @@ -51,6 +51,7 @@ src/models/PostIntentRequest.ts src/models/ReviewLatency.ts src/models/SpecMentor.ts src/models/SuccessMessage.ts +src/models/TokenRefreshResponse.ts src/models/UserPermissions.ts src/models/index.ts src/runtime.ts diff --git a/gen/js/chromestatus-openapi/src/apis/DefaultApi.ts b/gen/js/chromestatus-openapi/src/apis/DefaultApi.ts index 622be510..4b12bbde 100644 --- a/gen/js/chromestatus-openapi/src/apis/DefaultApi.ts +++ b/gen/js/chromestatus-openapi/src/apis/DefaultApi.ts @@ -39,6 +39,7 @@ import type { ReviewLatency, SpecMentor, SuccessMessage, + TokenRefreshResponse, } from '../models/index'; import { AccountResponseFromJSON, @@ -89,6 +90,8 @@ import { SpecMentorToJSON, SuccessMessageFromJSON, SuccessMessageToJSON, + TokenRefreshResponseFromJSON, + TokenRefreshResponseToJSON, } from '../models/index'; export interface AddFeatureCommentRequest { @@ -499,6 +502,20 @@ export interface DefaultApiInterface { */ postIntentToBlinkDev(requestParameters: PostIntentToBlinkDevRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise; + /** + * + * @summary Refresh the XSRF token + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApiInterface + */ + refreshTokenRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise>; + + /** + * Refresh the XSRF token + */ + refreshToken(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise; + /** * * @summary Remove a user from a component @@ -1253,6 +1270,32 @@ export class DefaultApi extends runtime.BaseAPI implements DefaultApiInterface { return await response.value(); } + /** + * Refresh the XSRF token + */ + async refreshTokenRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise> { + const queryParameters: any = {}; + + const headerParameters: runtime.HTTPHeaders = {}; + + const response = await this.request({ + path: `/currentuser/token`, + method: 'POST', + headers: headerParameters, + query: queryParameters, + }, initOverrides); + + return new runtime.JSONApiResponse(response, (jsonValue) => TokenRefreshResponseFromJSON(jsonValue)); + } + + /** + * Refresh the XSRF token + */ + async refreshToken(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise { + const response = await this.refreshTokenRaw(initOverrides); + return await response.value(); + } + /** * Remove a user from a component */ diff --git a/gen/js/chromestatus-openapi/src/models/TokenRefreshResponse.ts b/gen/js/chromestatus-openapi/src/models/TokenRefreshResponse.ts new file mode 100644 index 00000000..38056321 --- /dev/null +++ b/gen/js/chromestatus-openapi/src/models/TokenRefreshResponse.ts @@ -0,0 +1,68 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * chomestatus API + * The API for chromestatus.com. chromestatus.com is the official tool used for tracking feature launches in Blink (the browser engine that powers Chrome and many other web browsers). This tool guides feature owners through our launch process and serves as a primary source for developer information that then ripples throughout the web developer ecosystem. More details at: https://github.com/GoogleChrome/chromium-dashboard + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import { mapValues } from '../runtime'; +/** + * + * @export + * @interface TokenRefreshResponse + */ +export interface TokenRefreshResponse { + /** + * + * @type {string} + * @memberof TokenRefreshResponse + */ + token?: string; + /** + * + * @type {number} + * @memberof TokenRefreshResponse + */ + token_expires_sec?: number; +} + +/** + * Check if a given object implements the TokenRefreshResponse interface. + */ +export function instanceOfTokenRefreshResponse(value: object): value is TokenRefreshResponse { + return true; +} + +export function TokenRefreshResponseFromJSON(json: any): TokenRefreshResponse { + return TokenRefreshResponseFromJSONTyped(json, false); +} + +export function TokenRefreshResponseFromJSONTyped(json: any, ignoreDiscriminator: boolean): TokenRefreshResponse { + if (json == null) { + return json; + } + return { + + 'token': json['token'] == null ? undefined : json['token'], + 'token_expires_sec': json['token_expires_sec'] == null ? undefined : json['token_expires_sec'], + }; +} + +export function TokenRefreshResponseToJSON(value?: TokenRefreshResponse | null): any { + if (value == null) { + return value; + } + return { + + 'token': value['token'], + 'token_expires_sec': value['token_expires_sec'], + }; +} + diff --git a/gen/js/chromestatus-openapi/src/models/index.ts b/gen/js/chromestatus-openapi/src/models/index.ts index 4fbf1ea8..3d8451ad 100644 --- a/gen/js/chromestatus-openapi/src/models/index.ts +++ b/gen/js/chromestatus-openapi/src/models/index.ts @@ -45,4 +45,5 @@ export * from './PostIntentRequest'; export * from './ReviewLatency'; export * from './SpecMentor'; export * from './SuccessMessage'; +export * from './TokenRefreshResponse'; export * from './UserPermissions'; diff --git a/gen/py/chromestatus_openapi/.openapi-generator/FILES b/gen/py/chromestatus_openapi/.openapi-generator/FILES index b4a1d2a8..bc30425b 100644 --- a/gen/py/chromestatus_openapi/.openapi-generator/FILES +++ b/gen/py/chromestatus_openapi/.openapi-generator/FILES @@ -57,6 +57,7 @@ chromestatus_openapi/models/post_intent_request.py chromestatus_openapi/models/review_latency.py chromestatus_openapi/models/spec_mentor.py chromestatus_openapi/models/success_message.py +chromestatus_openapi/models/token_refresh_response.py chromestatus_openapi/models/user_permissions.py chromestatus_openapi/openapi/openapi.yaml chromestatus_openapi/test/__init__.py diff --git a/gen/py/chromestatus_openapi/chromestatus_openapi/controllers/default_controller.py b/gen/py/chromestatus_openapi/chromestatus_openapi/controllers/default_controller.py index 72e99f1e..7da0747d 100644 --- a/gen/py/chromestatus_openapi/chromestatus_openapi/controllers/default_controller.py +++ b/gen/py/chromestatus_openapi/chromestatus_openapi/controllers/default_controller.py @@ -27,6 +27,7 @@ from chromestatus_openapi.models.post_intent_request import PostIntentRequest # from chromestatus_openapi.models.review_latency import ReviewLatency # noqa: E501 from chromestatus_openapi.models.spec_mentor import SpecMentor # noqa: E501 from chromestatus_openapi.models.success_message import SuccessMessage # noqa: E501 +from chromestatus_openapi.models.token_refresh_response import TokenRefreshResponse # noqa: E501 from chromestatus_openapi import util @@ -327,6 +328,17 @@ def post_intent_to_blink_dev(feature_id, stage_id, gate_id, post_intent_request= return 'do some magic!' +def refresh_token(): # noqa: E501 + """Refresh the XSRF token + + # noqa: E501 + + + :rtype: Union[TokenRefreshResponse, Tuple[TokenRefreshResponse, int], Tuple[TokenRefreshResponse, int, Dict[str, str]] + """ + return 'do some magic!' + + def remove_user_from_component(component_id, user_id, component_users_request=None): # noqa: E501 """Remove a user from a component diff --git a/gen/py/chromestatus_openapi/chromestatus_openapi/models/__init__.py b/gen/py/chromestatus_openapi/chromestatus_openapi/models/__init__.py index 2dc0de81..7a25be40 100644 --- a/gen/py/chromestatus_openapi/chromestatus_openapi/models/__init__.py +++ b/gen/py/chromestatus_openapi/chromestatus_openapi/models/__init__.py @@ -45,4 +45,5 @@ from chromestatus_openapi.models.post_intent_request import PostIntentRequest from chromestatus_openapi.models.review_latency import ReviewLatency from chromestatus_openapi.models.spec_mentor import SpecMentor from chromestatus_openapi.models.success_message import SuccessMessage +from chromestatus_openapi.models.token_refresh_response import TokenRefreshResponse from chromestatus_openapi.models.user_permissions import UserPermissions diff --git a/gen/py/chromestatus_openapi/chromestatus_openapi/models/token_refresh_response.py b/gen/py/chromestatus_openapi/chromestatus_openapi/models/token_refresh_response.py new file mode 100644 index 00000000..7758334a --- /dev/null +++ b/gen/py/chromestatus_openapi/chromestatus_openapi/models/token_refresh_response.py @@ -0,0 +1,87 @@ +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from chromestatus_openapi.models.base_model import Model +from chromestatus_openapi import util + + +class TokenRefreshResponse(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, token=None, token_expires_sec=None): # noqa: E501 + """TokenRefreshResponse - a model defined in OpenAPI + + :param token: The token of this TokenRefreshResponse. # noqa: E501 + :type token: str + :param token_expires_sec: The token_expires_sec of this TokenRefreshResponse. # noqa: E501 + :type token_expires_sec: int + """ + self.openapi_types = { + 'token': str, + 'token_expires_sec': int + } + + self.attribute_map = { + 'token': 'token', + 'token_expires_sec': 'token_expires_sec' + } + + self._token = token + self._token_expires_sec = token_expires_sec + + @classmethod + def from_dict(cls, dikt) -> 'TokenRefreshResponse': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The TokenRefreshResponse of this TokenRefreshResponse. # noqa: E501 + :rtype: TokenRefreshResponse + """ + return util.deserialize_model(dikt, cls) + + @property + def token(self) -> str: + """Gets the token of this TokenRefreshResponse. + + + :return: The token of this TokenRefreshResponse. + :rtype: str + """ + return self._token + + @token.setter + def token(self, token: str): + """Sets the token of this TokenRefreshResponse. + + + :param token: The token of this TokenRefreshResponse. + :type token: str + """ + + self._token = token + + @property + def token_expires_sec(self) -> int: + """Gets the token_expires_sec of this TokenRefreshResponse. + + + :return: The token_expires_sec of this TokenRefreshResponse. + :rtype: int + """ + return self._token_expires_sec + + @token_expires_sec.setter + def token_expires_sec(self, token_expires_sec: int): + """Sets the token_expires_sec of this TokenRefreshResponse. + + + :param token_expires_sec: The token_expires_sec of this TokenRefreshResponse. + :type token_expires_sec: int + """ + + self._token_expires_sec = token_expires_sec diff --git a/gen/py/chromestatus_openapi/chromestatus_openapi/openapi/openapi.yaml b/gen/py/chromestatus_openapi/chromestatus_openapi/openapi/openapi.yaml index 25713fd2..02a04b3d 100644 --- a/gen/py/chromestatus_openapi/chromestatus_openapi/openapi/openapi.yaml +++ b/gen/py/chromestatus_openapi/chromestatus_openapi/openapi/openapi.yaml @@ -193,6 +193,18 @@ paths: description: The permissions and email of the user. summary: Get the permissions and email of the user x-openapi-router-controller: chromestatus_openapi.controllers.default_controller + /currentuser/token: + post: + operationId: refresh_token + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/TokenRefreshResponse' + description: Successfully refreshed the token. + summary: Refresh the XSRF token + x-openapi-router-controller: chromestatus_openapi.controllers.default_controller /external_reviews/{review_group}: get: operationId: list_external_reviews @@ -1483,6 +1495,19 @@ components: - cue title: DismissCueRequest type: object + TokenRefreshResponse: + example: + token_expires_sec: 0 + token: token + properties: + token: + title: token + type: string + token_expires_sec: + title: token_expires_sec + type: integer + title: TokenRefreshResponse + type: object SuccessMessage: example: message: Done diff --git a/gen/py/chromestatus_openapi/chromestatus_openapi/test/test_default_controller.py b/gen/py/chromestatus_openapi/chromestatus_openapi/test/test_default_controller.py index 43c4f870..d6f75ba8 100644 --- a/gen/py/chromestatus_openapi/chromestatus_openapi/test/test_default_controller.py +++ b/gen/py/chromestatus_openapi/chromestatus_openapi/test/test_default_controller.py @@ -26,6 +26,7 @@ from chromestatus_openapi.models.post_intent_request import PostIntentRequest # from chromestatus_openapi.models.review_latency import ReviewLatency # noqa: E501 from chromestatus_openapi.models.spec_mentor import SpecMentor # noqa: E501 from chromestatus_openapi.models.success_message import SuccessMessage # noqa: E501 +from chromestatus_openapi.models.token_refresh_response import TokenRefreshResponse # noqa: E501 from chromestatus_openapi.test import BaseTestCase @@ -371,6 +372,21 @@ class TestDefaultController(BaseTestCase): self.assert200(response, 'Response body is : ' + response.data.decode('utf-8')) + def test_refresh_token(self): + """Test case for refresh_token + + Refresh the XSRF token + """ + headers = { + 'Accept': 'application/json', + } + response = self.client.open( + '/api/v0/currentuser/token', + method='POST', + headers=headers) + self.assert200(response, + 'Response body is : ' + response.data.decode('utf-8')) + def test_remove_user_from_component(self): """Test case for remove_user_from_component diff --git a/openapi/api.yaml b/openapi/api.yaml index 2f8a748a..7063083c 100644 --- a/openapi/api.yaml +++ b/openapi/api.yaml @@ -307,6 +307,17 @@ paths: application/json: schema: $ref: '#/components/schemas/SuccessMessage' + /currentuser/token: + post: + summary: Refresh the XSRF token + operationId: refreshToken + responses: + '200': + description: Successfully refreshed the token. + content: + application/json: + schema: + $ref: '#/components/schemas/TokenRefreshResponse' /external_reviews/{review_group}: get: summary: List features whose external reviews are incomplete @@ -1028,6 +1039,13 @@ components: - progress-checkmarks required: - cue + TokenRefreshResponse: + type: object + properties: + token: + type: string + token_expires_sec: + type: integer SuccessMessage: type: object properties: