token refresh (#4255)
This commit is contained in:
Родитель
532109ed78
Коммит
dd4a0a4d6b
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<MessageResponse>;
|
||||
|
||||
/**
|
||||
*
|
||||
* @summary Refresh the XSRF token
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof DefaultApiInterface
|
||||
*/
|
||||
refreshTokenRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<TokenRefreshResponse>>;
|
||||
|
||||
/**
|
||||
* Refresh the XSRF token
|
||||
*/
|
||||
refreshToken(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenRefreshResponse>;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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<runtime.ApiResponse<TokenRefreshResponse>> {
|
||||
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<TokenRefreshResponse> {
|
||||
const response = await this.refreshTokenRaw(initOverrides);
|
||||
return await response.value();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a user from a component
|
||||
*/
|
||||
|
|
|
@ -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'],
|
||||
};
|
||||
}
|
||||
|
|
@ -45,4 +45,5 @@ export * from './PostIntentRequest';
|
|||
export * from './ReviewLatency';
|
||||
export * from './SpecMentor';
|
||||
export * from './SuccessMessage';
|
||||
export * from './TokenRefreshResponse';
|
||||
export * from './UserPermissions';
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Загрузка…
Ссылка в новой задаче