Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is access_type = Online appropriate? :OAuth2 - Google API

When requesting OAuth credentials, I can specify the access_type to be Offline or Online.

Opting for the Online access type forces the users to approve access to my app each time they login. Why is that? Hasn't the user already approved my app?

Update #1:

I have my approval_prompt set to 'auto'.
If I just log out of Google without deleting any cookies, it doesn't prompt me again. But deleting the cookies brings back the grant screen.

Update #2:

It works fine through the OAuth Playground. http://code.google.com/oauthplayground/

Using OAuth 2.0 for Web Server Applications https://developers.google.com/accounts/docs/OAuth2WebServer

Update #3: Relevant code snippets

Helper method to generate OAuth URL

def build_auth_uri
    return @client.authorization.authorization_uri(
     :access_type => :online,
     :approval_prompt => :auto
    ).to_s 
end

Calling the Helper method in the View

<a href="<%= build_auth_uri %>">  Connect Me! </a>

Generated OAuth URL on the webpage

https://accounts.google.com/o/oauth2/auth?access_type=online&approval_prompt=auto&redirect_uri=http://localhost:3000/gclient/gcallback&response_type=code
like image 914
Diwa Iyer Avatar asked Jul 13 '12 17:07

Diwa Iyer


People also ask

Which OAuth grant type is appropriate for Microservices?

OAuth 2 is an authorization framework, a security concept for rest API( Read as MicroService), about how you authorize a user to get access to a resource from your resource server by using token.

Should I use OAuth2 for my API?

You only really need OAuth2 and OpenID Connect if you'd like your users to give consent ("i.e. I want to allow this app access to my personal data"). You do not need OAuth2 to generate a JSON Web Token, a Personal Access Token, a Native Mobile App Session Token.

Can a public IP address be used as Google OAuth redirect URI?

This is not currently supported. I filed a feature request and will update on progress. Update: Essential app verification activities have continued to make support of IP address-based apps unlikely. These verification activities are necessary to provide protections against abuse of user accounts.


1 Answers

There is one other parameter that comes into play in these flows and I suspect you're running into it. It's the approval_prompt parameter.

When access_type=online you are also allowed to specify a value for approval_prompt. If it is set to approval_prompt=force, your user will always be prompted, even if they have already granted.

On the other hand, when access_type=offline, approval_prompt can only be set to approval_prompt=force, but to make up for this restriction you're also provided a refresh_token which you can use to refresh your access token.

Check the URL that your access_type=online is opening. Try setting approval_prompt=auto. The grant screen should only appear the first time.

like image 168
mimming Avatar answered Sep 17 '22 11:09

mimming