#Swift's access control rules

1 messages · Page 1 of 1 (latest)

swift marsh
#

any suggestions. i am currently just circulative marking public object and what not.

violet haven
#

Which variable can't you see?

swift marsh
#

i cant access:

try await app.oauth.google.make<EmailAccessToken>(service: oauthGoogle)
#

defined in;

public extension Application.OAuth {
  public var google: Google {
    .init(_oauth: self)
  }
...

having the function:

    public func make<Token>(service: GoogleService) where Token: GoogleToken & Authenticatable {
      let router = OAuthRouter<GoogleService, Token>(service)
      
      try await self._oauth._application.oauth
        .services.register(app: self._oauth._application, service, router: router)
    }
  }

defined in its type value

violet haven
#

So you can't access the google variable or the make function?

swift marsh
#

neither

violet haven
#

What's the error?

swift marsh
#

i can access app.oauth.services.register though and it is of type Application.oauth i assume to be correct when i believe that the access control for the application object is not in question.

#

Value of type 'Application.OAuth' has no member 'google'

violet haven
#

Hmm looks like it should work

#

Make sure you're using the latest packages

#

And best option is to try it in the OAuth Tests (without using @testable)

#

(And check from the command line and not Xcode)

swift marsh
#

will have a look tomorrow

elder glacier
#

you did explicitly import the module right?

solemn inlet
#

I would first clean up your access control usage - in some places you’re using ‘public extension’ with explicitly declared public properties, in some places you’re not. I try to keep a code style just writing extensions as extension - then expose what you need explicitly as public

swift marsh
swift marsh
swift marsh
#

its driving me nuts

solemn inlet
#

Okay I've got a simple answer for you 😅

#

Since your Package.swift is defining OAuth as a target, it is only including the source from Sources/OAuth

#

You need to move the Vendor folder inside OAuth

#

Or if you really want to keep that structure, define the target like so with path set explicitly:

.target(
  name: "OAuth",
  dependencies: [
    .product(name: "OAuthKit", package: "oauth-kit"),
    .product(name: "Vapor", package: "vapor")
  ],
  path: "Sources"
)
#

there are some other issues too though - your make<Token> method needs to be rewritten to include the actual token type as a parameter rather than trying to specialise at the call site with app.oauth.google.make<EmailAccessToken>(...)

#

this is better

public func make<Token>(service: GoogleService, tokenType: Token.Type) async throws where Token: GoogleToken & Authenticatable {
// ...
}
#

then just add Authenticatable to your EmailAccessToken and you can call

try await app.oauth.google.make(service: oauthGoogle, tokenType: EmailAccessToken.self)

and everything compiles just fine 😄

swift marsh
rotund wingBOT
swift marsh
#

@violet haven what do you think. how does this look

violet haven
#

What does what look?

swift marsh
#

the package its done. its awesome. tell me its awesome 🙂