---
title: "obtain(withRight:flags:)"
framework: securityfoundation
role: symbol
role_heading: Instance Method
path: "securityfoundation/sfauthorization/obtain(withright:flags:)"
---

# obtain(withRight:flags:)

Authorizes and preauthorizes one specific right.

## Declaration

```swift
func obtain(withRight rightName: AuthorizationString!, flags: AuthorizationFlags) throws
```

## Parameters

- `rightName`: The name of an authorization right.
- `flags`: A bit mask for specifying authorization options. See doc://com.apple.securityfoundation/documentation/SecurityFoundation/SFAuthorization/obtain(withRights:flags:environment:authorizedRights:) for details about possible flag values.

## Return value

Return value true if operation completes successfully. Discussion Use this method to authorize or preauthorize a single right. note: In Swift, this method returns Void and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Authorizing rights

- [obtain(withRights:flags:environment:authorizedRights:)](securityfoundation/sfauthorization/obtain(withrights:flags:environment:authorizedrights:).md)
