OAuth2 Credentials Flow on GAE with google-auth

Since oauth2client library seems to be deprecated, OAuth2 credentials flow should be written with google-auth library recommended.

from flask import redirect, session, url_for


def credentials_to_dict(credentials):
    return {
        'token': credentials.token,
        'refresh_token': credentials.refresh_token,
        'token_uri': credentials.token_uri,
        'client_id': credentials.client_id,
        'client_secret': credentials.client_secret,
        'scopes': credentials.scopes
    }


@credential.route('/authorize')
def authorize():
    flow = Flow.from_client_secrets_file('client_secret.json', scopes=SCOPES)
    flow.redirect_uri = url_for('credential.oauth2callback', _external=True)
    authorization_url, state = flow.authorization_url(
        access_type='offline',
        include_granted_scopes='true'
    )
    session['state'] = state
    return redirect(authorization_url)


@credential.route('/oauth2callback')
def oauth2callback():
    flow = Flow.from_client_secrets_file(
        'client_secret.json',
        scopes=SCOPES,
        state=session['state']
    )
    flow.redirect_uri = url_for('credential.oauth2callback', _external=True)
    flow.fetch_token(authorization_response=request.url)
    session['credentials'] = credentials_to_dict(flow.credentials)
    return redirect(url_for('schedule.check_calendar'))

@schedule.route('/check', methods=['GET'])
def check_calendar():
    if 'credentials' not in session:
        return redirect(url_for('credential.authorize'))    
    get_unavailable_date()