@@ -73,6 +73,8 @@ open class Auth {
7373 case userSuspended
7474 /// The access token has expired.
7575 case expiredAccessToken
76+ /// The access token does not have the required scope to access the route.
77+ case missingScope( Auth . TokenScopeError )
7678 /// An unspecified error.
7779 case other
7880
@@ -104,6 +106,10 @@ open class Auth {
104106 var d = [ String: JSON] ( )
105107 d [ " .tag " ] = . str( " expired_access_token " )
106108 return . dictionary( d)
109+ case . missingScope( let arg) :
110+ var d = Serialization . getFields ( Auth . TokenScopeErrorSerializer ( ) . serialize ( arg) )
111+ d [ " .tag " ] = . str( " missing_scope " )
112+ return . dictionary( d)
107113 case . other:
108114 var d = [ String: JSON] ( )
109115 d [ " .tag " ] = . str( " other " )
@@ -125,6 +131,9 @@ open class Auth {
125131 return AuthError . userSuspended
126132 case " expired_access_token " :
127133 return AuthError . expiredAccessToken
134+ case " missing_scope " :
135+ let v = Auth . TokenScopeErrorSerializer ( ) . deserialize ( json)
136+ return AuthError . missingScope ( v)
128137 case " other " :
129138 return AuthError . other
130139 default :
@@ -444,6 +453,37 @@ open class Auth {
444453 }
445454 }
446455
456+ /// The TokenScopeError struct
457+ open class TokenScopeError : CustomStringConvertible {
458+ /// The required scope to access the route.
459+ public let requiredScope : String
460+ public init ( requiredScope: String ) {
461+ stringValidator ( ) ( requiredScope)
462+ self . requiredScope = requiredScope
463+ }
464+ open var description : String {
465+ return " \( SerializeUtil . prepareJSONForSerialization ( TokenScopeErrorSerializer ( ) . serialize ( self ) ) ) "
466+ }
467+ }
468+ open class TokenScopeErrorSerializer : JSONSerializer {
469+ public init ( ) { }
470+ open func serialize( _ value: TokenScopeError ) -> JSON {
471+ let output = [
472+ " required_scope " : Serialization . _StringSerializer. serialize ( value. requiredScope) ,
473+ ]
474+ return . dictionary( output)
475+ }
476+ open func deserialize( _ json: JSON ) -> TokenScopeError {
477+ switch json {
478+ case . dictionary( let dict) :
479+ let requiredScope = Serialization . _StringSerializer. deserialize ( dict [ " required_scope " ] ?? . null)
480+ return TokenScopeError ( requiredScope: requiredScope)
481+ default :
482+ fatalError ( " Type error deserializing " )
483+ }
484+ }
485+ }
486+
447487
448488 /// Stone Route Objects
449489
0 commit comments