Hi. I'm using Scala and Jersey on the server.

I've used a trait to encapsulate the auth logic.


trait Security {
  def provider: ProfileProvider

  def withSecurity(info: UriInfo)(f: (Profile) => ResponseBuilder):
ResponseBuilder = {
    val profile = provider.currentProfile()
    profile match {
      case Some(x) => f(x)
      case None => Response.status(403)
    }
  }

  def withSecurity(f: (Profile) => ResponseBuilder): ResponseBuilder = {
    val profile = provider.currentProfile()
    profile match {
      case Some(x) => f(x)
      case None => Response.status(403)
    }
  }
}

The code for the ProfileProvider is here:

trait ProfileProvider {
  def currentProfile(): Option[Profile]
}

object ProfileProvider {
  def apply(): ProfileProvider = GaeProfileProvider

  private object GaeProfileProvider extends ProfileProvider {
    val factory = OAuthServiceFactory.getUserService;
    val profileService = GaeProfileService

    def currentProfile() = {
      val user = try {
        Option(factory.getCurrentUser)
      }
      catch {
        case e : OAuthRequestException => None
      }

      user match {
        case Some(x) => {
          val username = x.getEmail
          val loggedUser = profileService.retrieveByUsername(username)
          loggedUser match  {
              //TODO: is it wise to create the user when we first log in?
            case None =>
              val profile = Profile(None, username, "Unknown", Sex.Male, new
LocalDate(), "Unknown")
              Some(profileService.save(profile))
            case z => z
          }
        }
        case None => None
      }
    }
  }
}


Anything obviously wrong?

I never actually reach this code as there was something in front preventing
that.

-Erlend


On Mon, Aug 29, 2011 at 9:13 PM, Ikai Lan (Google) <[email protected]>wrote:

> Looks like you're trying to implement a consumer. You don't need to enable
> federated login. Can you provide your server side provider code? You can't
> use OAuth to auth against something expecting UserService.
>
> --
> Ikai Lan
> Developer Programs Engineer, Google App Engine
> plus.ikailan.com | twitter.com/ikai
>
>
>
> On Mon, Aug 29, 2011 at 1:39 AM, Erlend Hamnaberg <[email protected]>wrote:
>
>> Hi.
>>
>> I am attempting to use OAuth in my appengine app.
>> I can't even get to the app, as google accounts hijacks my session before
>> that happens.
>>
>> Do I need to enable federated login?
>>
>> App id: sykle-til-jobben
>>
>> I've attached the code I've used to connect to appengine
>>
>> http://code.google.com/appengine/docs/java/oauth/
>> is really sparse with documentation.
>>
>> Looking at:
>> http://code.google.com/appengine/docs/python/oauth/overview.html
>>
>> http://code.google.com/apis/accounts/docs/OAuth_ref.html
>>
>> Does not help me either.
>>
>> What have I done wrong?
>>
>> --
>> Erlend
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google App Engine for Java" group.
>> To post to this group, send email to
>> [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine-java?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to