aboutsummaryrefslogtreecommitdiffstats
path: root/genericparser/packages/serializers/subscription_auth_data.py
blob: 9248fb12e5ef100129e12fe23ec02263e8862053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright (C) 2019 Verizon. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from rest_framework import serializers

from genericparser.packages import const


class OAuthCredentialsSerializer(serializers.Serializer):
    clientId = serializers.CharField(
        help_text="Client identifier to be used in the access token "
        "request of the OAuth 2.0 client credentials grant type.",
        required=False,
        max_length=255,
        allow_null=False
    )
    clientPassword = serializers.CharField(
        help_text="Client password to be used in the access token "
        "request of the OAuth 2.0 client credentials grant type.",
        required=False,
        max_length=255,
        allow_null=False
    )
    tokenEndpoint = serializers.CharField(
        help_text="The token endpoint from which the access token can "
        "be obtained.",
        required=False,
        max_length=255,
        allow_null=False
    )


class BasicAuthSerializer(serializers.Serializer):
    userName = serializers.CharField(
        help_text="Username to be used in HTTP Basic authentication.",
        max_length=255,
        required=False,
        allow_null=False
    )
    password = serializers.CharField(
        help_text="Password to be used in HTTP Basic authentication.",
        max_length=255,
        required=False,
        allow_null=False
    )


class SubscriptionAuthenticationSerializer(serializers.Serializer):
    authType = serializers.ListField(
        child=serializers.ChoiceField(required=True, choices=const.AUTH_TYPES),
        help_text="Defines the types of Authentication / Authorization "
        "which the API consumer is willing to accept when "
        "receiving a notification.",
        required=True
    )
    paramsBasic = BasicAuthSerializer(
        help_text="Parameters for authentication/authorization using BASIC.",
        required=False,
        allow_null=False
    )
    paramsOauth2ClientCredentials = OAuthCredentialsSerializer(
        help_text="Parameters for authentication/authorization using "
        "OAUTH2_CLIENT_CREDENTIALS.",
        required=False,
        allow_null=False
    )