-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Signup for NativeAuth #1949
Signup for NativeAuth #1949
Changes from 5 commits
83541ef
fcfed85
e69a2f8
81cc4cb
52b0333
1d6b5c7
b9c209e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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.client | ||
|
||
import com.microsoft.identity.common.java.providers.nativeauth.responses.UserAttributeApiResult | ||
|
||
/** | ||
* RequiredUserAttribute represents details about the account attributes required by the server. | ||
*/ | ||
data class RequiredUserAttribute( | ||
//Name of the attribute | ||
val attributeName: String?, | ||
|
||
//Data type for the attribute | ||
val type: String?, | ||
|
||
//If the attribute is required | ||
val required: Boolean?, | ||
|
||
//Attribute value should match the constraints | ||
val options: RequiredUserAttributeOptions? | ||
) | ||
|
||
internal fun List<UserAttributeApiResult>.toListOfRequiredUserAttribute(): List<RequiredUserAttribute> { | ||
return this.map { it.toRequiredUserAttribute() } | ||
} | ||
|
||
internal fun UserAttributeApiResult.toRequiredUserAttribute(): RequiredUserAttribute { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Javadoc on these two methods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
return RequiredUserAttribute( | ||
attributeName = this.name, | ||
type = this.type, | ||
required = this.required, | ||
options = this.options?.toListOfRequiredUserAttributeOptions() | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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.client | ||
|
||
import com.microsoft.identity.common.java.providers.nativeauth.responses.UserAttributeOptionsApiResult | ||
|
||
/** | ||
* RequiredUserAttributeOptions contains the regular expression that the attribute value must match. | ||
*/ | ||
data class RequiredUserAttributeOptions( | ||
val regex: String? | ||
) | ||
|
||
internal fun List<UserAttributeOptionsApiResult>.toListOfRequiredUserAttributeOptions(): List<RequiredUserAttributeOptions> { | ||
return this.map { it.toListOfRequiredUserAttributeOptions() } | ||
} | ||
|
||
fun UserAttributeOptionsApiResult.toListOfRequiredUserAttributeOptions(): RequiredUserAttributeOptions { | ||
return RequiredUserAttributeOptions( | ||
regex = regex | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.microsoft.identity.client | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LICENSE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
|
||
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>) { | ||
companion object Builder { | ||
private const val CITY = "city" | ||
private const val COUNTRY = "country" | ||
private const val DISPLAY_NAME = "displayName" | ||
private const val EMAIL_ADDRESS = "email" | ||
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 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 email address for the user | ||
* @param emailAddress: Email address for the user | ||
*/ | ||
fun emailAddress(emailAddress: String): Builder { | ||
userAttributes[EMAIL_ADDRESS] = emailAddress | ||
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 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wasn't |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what we mean by these being required. There is a boolean flag here..so if require boolean was false then will these still be considered required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These attributes are requested (required) by the server so they are called
RequiredUserAttribute
. The required field denotes whether it is mandatory for the attribute to be sent. The class names reflect the attribute names we get from the REST APIs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the boolean here will always be true. Honestly the naming here is too confusing. It sounds like the required boolean means something else but I'm not sure what it means
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the naming is a bit confusing but it represents the attribute names from the REST API. I will talk to API folks to see if we can rename it. That change will be outside of this PR.