<!--
{
  "availability" : [
    "macOS: 10.10.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SecurityFoundation",
  "identifier" : "/documentation/SecurityFoundation/SFAuthorization/obtain(withRight:flags:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Security Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)SFAuthorization(im)obtainWithRight:flags:error:"
  },
  "title" : "obtain(withRight:flags:)"
}
-->

# obtain(withRight:flags:)

Authorizes and preauthorizes one specific right.

```
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 [`obtain(withRights:flags:environment:authorizedRights:)`](/documentation/SecurityFoundation/SFAuthorization/obtain(withRights:flags:environment:authorizedRights:)) for details about possible flag values.

## Return value

<doc://com.apple.documentation/documentation/Swift/true> if operation completes successfully.

## Discussion

Use this method to authorize or preauthorize a single right.

> Handling Errors in Swift: 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](https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html) in [The Swift Programming Language](https://docs.swift.org/swift-book/) and <doc://com.apple.documentation/documentation/Swift/about-imported-cocoa-error-parameters>.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)