-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathUserAttributes.kt
More file actions
156 lines (140 loc) · 5.15 KB
/
Copy pathUserAttributes.kt
File metadata and controls
156 lines (140 loc) · 5.15 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright (c) Microsoft Corporation.
// All rights reserved.
//
// This code is licensed under the MIT License.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package com.microsoft.identity.nativeauth
import com.microsoft.identity.common.java.util.ObjectMapper
/**
* UserAttributes is a helper class for a client to provide user attributes required for signup
* operation in Native Auth
*/
class UserAttributes(internal val userAttributes: Map<String, String>) {
class Builder {
companion object {
private const val CITY = "city"
private const val COUNTRY = "country"
private const val DISPLAY_NAME = "displayName"
private const val GIVEN_NAME = "givenName"
private const val JOB_TITLE = "jobTitle"
private const val POSTAL_CODE = "postalCode"
private const val STATE = "state"
private const val STREET_ADDRESS = "streetAddress"
private const val SURNAME = "surname"
private const val FLAT_USERNAME = "flatusername"
}
private val userAttributes = mutableMapOf<String, String>()
/**
* Sets the city for user
* @param city: City for user
*/
fun city(city: String): Builder {
userAttributes[CITY] = city
return this
}
/**
* Sets the country for the user
* @param country: Country for the user
*/
fun country(country: String): Builder {
userAttributes[COUNTRY] = country
return this
}
/**
* Sets the name for display purposes for the user
* @param displayName: Display name for the user
*/
fun displayName(displayName: String): Builder {
userAttributes[DISPLAY_NAME] = displayName
return this
}
/**
* Sets the given name for the user
* @param givenName: Given name for the user
*/
fun givenName(givenName: String): Builder {
userAttributes[GIVEN_NAME] = givenName
return this
}
/**
* Sets the job title for the user
* @param givenName: Given name for the user
*/
fun jobTitle(jobTitle: String): Builder {
userAttributes[JOB_TITLE] = jobTitle
return this
}
/**
* Sets the given name for the user
* @param givenName: Given name for the user
*/
fun postalCode(postalCode: String): Builder {
userAttributes[POSTAL_CODE] = postalCode
return this
}
/**
* Sets the state/province for the user
* @param state: State/province for the user
*/
fun state(state: String): Builder {
userAttributes[STATE] = state
return this
}
/**
* Sets the street address for the user
* @param streetAddress: Street address for the user
*/
fun streetAddress(streetAddress: String): Builder {
userAttributes[STREET_ADDRESS] = streetAddress
return this
}
/**
* Sets the surname for the user
* @param surname: Surname for the user
*/
fun surname(surname: String): Builder {
userAttributes[SURNAME] = surname
return this
}
/**
* Sets the flat username for the user
* @param flatUsername: Flat username for the user
*/
fun flatUsername(flatUsername: String): Builder {
userAttributes[FLAT_USERNAME] = flatUsername
return this
}
/**
* Sets any custom attribute for the use
* @param key: Name of the attribute
* @param value: Attribute value
*/
fun customAttribute(key: String, value: String): Builder {
userAttributes[key] = value
return this
}
fun build(): UserAttributes {
return UserAttributes(userAttributes)
}
}
}
internal fun UserAttributes.toMap(): Map<String, String> {
return ObjectMapper.constructMapFromObject(userAttributes)
}