{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • Edge/API Management /
avatar image
0
Question by AlayVakil · Jan 19, 2017 at 07:48 AM · 739 Views responseoauthv2headergenerate token

Oauth V2 GenerateAccessToken in response flow

I want to generate an access token in the proxy response flow.

As mentioned in Oauth policy documentation I have set the request.header.Authorization to base64(client_id:client_secret) before the Oauth policy execution. Even then it gives me an error like :

{
  "fault": {
    "faultstring":"invalid_request",
    "detail": {
      "errorcode":"invalid_request"
    }
  }
}


My Oauthv2 policy uses external variables for token, expiry time and grant_type as follows :
<OAuthV2 name="OAuth2-generate-token">
  <Operation>GenerateAccessToken</Operation>
  <ExternalAccessToken>flow.idm.accessToken</ExternalAccessToken>
  <StoreToken>true</StoreToken>   
  <SupportedGrantTypes>       
    <GrantType>password</GrantType>    
  </SupportedGrantTypes>    
  <GrantType>flow.grant_type</GrantType>   
  <GenerateResponse enabled="false"/>    
  <ExpiresIn ref="flow.jwt.expiry">3600000</ExpiresIn>
</OAuthV2>
Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

5 Answers

  • Sort: 
avatar image
0
Best Answer

Answer by Mahammad Feroz · Jan 19, 2017 at 09:23 AM

@AlayVakil, username and password are required fields for the password grant. Pls pass them and check.

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by seamaslee   · Jan 20, 2017 at 05:03 AM

Hi Alay,

Just reoccur you error.

{
  "fault": {
    "faultstring": "invalid_request",
    "detail": {
      "errorcode": "invalid_request"
    }
  }
}

I think you have passed the client_id and client_secret parameters, and they are verified succeed.

The issue is duo to config the Oauth parameter flow.grant_type,

<GrantType>flow.grant_type</GrantType>

You configure the GrantType element like the following

<GrantType>request.formparam.grant_type</GrantType>

This means the inbound request must pass grant_type as request parameter (form urlencoded).

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Sachhida Das   · Jan 21, 2017 at 03:58 AM

@AlayVakil : use below policy for grant type password:

<OAuthV2 name="OAuth-v20-2"> 
  <DisplayName>OAuth-v20-2</DisplayName>
  <Operation>GenerateAccessToken</Operation> 
  <ExpiresIn>360000000</ExpiresIn> 
  <SupportedGrantTypes> 
    <GrantType>password</GrantType> 
  </SupportedGrantTypes> 
  <GrantType>request.queryparam.grant_type</GrantType> 
  <UserName>request.queryparam.username</UserName> 
  <PassWord>request.queryparam.password</PassWord> 
  <GenerateResponse/>
</OAuthV2>

request url would be like below:

(proxy_resource_path)?username=XXXXXX&password=YYYYYY&grant_type=password

set the header Authorization to base64(client_id:client_secret)

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Wei Shen · Jan 28, 2017 at 04:43 AM

@AlayVakil

I was in the same boat not long ago, with exactly same invalid_request error. Use 3rd party token is not well implemented and documented. Here is what I got so far to cache an external access token

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OAuthV2 async="false" continueOnError="false" enabled="true" name="StoreExternalToken">
    <DisplayName>Store External Token</DisplayName>
    <Properties/>
    <Operation>GenerateAccessToken</Operation>
    <SupportedGrantTypes>
        <!-- Only client_credentials is supported for storing external token -->
        <GrantType>client_credentials</GrantType>
    </SupportedGrantTypes>
    <GrantType>override_grant_type</GrantType>
    <ExternalAuthorization>true</ExternalAuthorization>
    <ExternalAccessToken>request.formparam.token</ExternalAccessToken>
    <ExpiresIn ref="token_expiration">300000</ExpiresIn>
    <AppEndUser>token_user</AppEndUser>
    <!-- Overwrite scope from external token doesn't work. apigee bug?? -->
    <Scope>token_scope</Scope>
    <Attributes>
        <Attribute name="claims" ref="token_claims"/>
    </Attributes>
    <GenerateResponse enabled="false"/>
    <GenerateErrorResponse enabled="true"/>
    <StoreToken>true</StoreToken>
    <Tokens/>
</OAuthV2>

The "override_grant_type" is a flow variable name, with value of "client_credentials". You can choose your name variable name, but has to be a variable in the OAuth2 policy. I've tried putting a static value but doesn't work. So you will need another policy to set this variable to value "client_credentials".

The "token_scope" is another variable holding the scope value from the external token, but it wasn't able to override the scope of this policy. You will get empty scope for the stored external token, which basically defeat the purpose of using an external token.

I hope apigee folks can shed some light, and address this issue.

Comment
Add comment Show 1 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image davissean ♦   · Jan 29, 2017 at 06:39 PM 0
Link

Hi @Wei Shen,

With regard to the <Scope>, is the value of the scope you are populating part of the Allowed Scopes defined in the API Product?

By adding it there, it should be added to the scope of the Token.

Thanks, Sean

avatar image
0

Answer by Wei Shen · Jan 30, 2017 at 04:10 PM

@Sean Davis

The value of "token_scope" is subset of allowed scopes in API product.

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to calculate response time? 3 Answers

How to access the HTTPCLIENT response data 1 Answer

Adding custom attributes to OAuthV2 generated token 4 Answers

Using API proxy as a URL shortening service 3 Answers

Is implicit grant_type in OAuthV2 policy actually useful? 3 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2019 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Members
  • Badges